CakePHP call to a member function on a non object .

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lovelf
Forum Contributor
Posts: 153
Joined: Wed Nov 05, 2008 12:06 am

CakePHP call to a member function on a non object .

Post by lovelf »

Does anyone determine what's wrong with this code?

Code: Select all

<?php
class PostsController extends AppController
{
var $name='Posts';

function index(){
$posts=$this->post->find('all',array('id','title','content','created','modified','published'), 'id DESC');
$this->set(compact('posts'));
}

}
?>
Call to a member function find() on a non-object in E:\xampp\htdocs\cake\app\controllers\posts_controller.php on line 7
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: CakePHP call to a member function on a non object .

Post by Jonah Bron »

If that's your entire class, then there is apparently no "post" variable. $this is a reference to an objects self, and it has no property "post".
Post Reply