Problem:
CalePHP 3.0 is different than it previous versions. Lot of things removed. In new CakePHP 3.0How to use Model in CakePHP 3.0 using new ORM model
Solution:
See below exampleExample:
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
{
}
?>
0 comments:
Post a Comment