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

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive