Jimothey
Jimothey

Reputation: 2434

CakePHP, getting another models info into the page controller

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.

Upvotes: 0

Views: 325

Answers (2)

nappo
nappo

Reputation: 594

You can load the model in your PagesController's admin_index() function:

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

Now you have $posts available in your pages' view file. (Adjust find method to your needs)

Upvotes: 1

Krishna
Krishna

Reputation: 1540

try this :

$this->loadmodel('Post');
$posts = $this->Post->find('all',array('conditions'=>array('Post.id'=>'1','Post.field'=>'value')));
$this->set('posts',$posts);

Upvotes: 1

Related Questions