0

I'm trying to build an admin page using the pages controller and a admin_index() function. I need to get a list of all Posts with a certain status and display them on this page. How can I grab these in the pages controller so I can then display them in the view.

Many thanks in advance.

4

2 に答える 2

1

PagesControllerのadmin_index()関数でモデルをロードできます。

$this->loadModel('Post');
$posts = $this->Post->find('all', array(
    'conditions' => array('Post.status' => 'your_filter')
);
$this->set(compact('posts'));

これで、ページのビューファイルで$postsを使用できるようになりました。(検索方法をニーズに合わせて調整します)

于 2012-08-03T10:47:19.613 に答える
1

これを試して :

$this->loadmodel('Post');
$posts = $this->Post->find('all',array('conditions'=>array('Post.id'=>'1','Post.field'=>'value')));
$this->set('posts',$posts);
于 2012-08-03T10:47:46.730 に答える