For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Tuesday, April 07, 2015

Model in CakePHP 3.0

Problem:

CalePHP 3.0 is different than it previous versions. Lot of things removed. In new CakePHP 3.0  
How to use Model in CakePHP 3.0 using new ORM model

Solution:

See below example

Example:


Create ArticlesController.php controller in "src\Controller" folder
<?php
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
class ArticlesController extends AppController
{
     public function index() {

     }
    public function showarticles() {
        $data = $this->Articles->find();
        foreach ($data as $row){
          echo $row->title;
       }
    }
}

ArticlesTable.php in "src\Model\Table" folder
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
class ArticlesTable extends Table
{

}
?>

Create Article.php in "src\Model\Entity" folder
<?php
// src/Model/Entity/Article.php
namespace App\Model\Entity;
use Cake\ORM\Entity;
class Article extends Entity
{
       
}
?>






Share:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive