我正在使用 cakephp 2.4 开发一个新闻门户。我有 2 个表格(类别和文章)现在我想通过此链接显示给定类别的文章:http://mydomain/category/2
我的类别模型:
class Category extends AppModel {
var $name = 'Category';
var $hasMany = array('Article');
}
我的文章模型:
class Article extends AppModel {
var $name = 'Article';
var $belongsTo = Array('Category');
文章控制者:
class ArticlesController extends AppController {
var $name = 'Articles';
var $scaffold;
function lists()
{
$this->Article->recursive = 1;
$myCat = $this->Category->find('all', array('order' => 'Category.id ASC'));
return $this->Article->lists($myCat);
}
}
我的类别控制器:
class CategoriesController extends AppController {
var $name = 'Categories';
var $scaffold;
function index()
{
$this->Category->recursive = 1;
$this->set('showCat', $this->Category->find('all'));
}
}
现在我很困惑如何显示文章列表http://mydomain/category/2
请帮我