Your model name is Post not Posts so change Posts->find()
to Post->find()
.
Also for example in Post->fetch()
your are in Post model scope so use $this->find()
not $this->Post->find().
Read about cake conventions. Model names are singular.
Pergunta
Hello All I checked all the posts regarding this ERROR. But my context is little different. Please have a look.
class Post extends AppModel {
function add($data){
if (!empty($data)) {
$this->create();
if($this->save($data)) {
return true ;
}
}
}
//For Add Action
function fetchdata() {
return $this->find('all',array( 'order' => array('id DESC') ) );
}
//For Edit Action
function fetch() {
return $this->Posts->find('all',array( 'order' => array('id DESC')) );
}
function getdata($id) {
return $this->Posts->find('all',array( 'conditions' => array('id'=>$id)) );
}
//For Index Action
function retrievedata($id) {
return $this->Posts->find('all',array( 'conditions' => array('id'=>$id)) );
}
}
//For Edit Action
function fetch() {
return $this->Posts->find('all',array( 'order' => array('id DESC')) );
}
class PostsController extends AppController {
public $uses = array('Post');
public function index(){
if(isset($this->request->params['pass'][0])){
$this->set('showdata',$this->Post->retrievedata($this->request->params['pass'][0]));
}
}
public function add()
{
if(!empty($this->request->data)){
if($this->Post->add($this->request->data)==true){
$this->redirect(array('action'=>'index'));
}
}
}
public function edit(){
$this->set('post',$this->Post->fetch());
if(isset($this->request->params['pass'][0])){
$this->set('showdata',$this->Post->getdata($this->request->params['pass'][0]));
}
}
}
public function edit(){
$this->set('post',$this->Post->fetch());
if(isset($this->request->params['pass'][0])){
$this->set('showdata',$this->Post->getdata($this->request->params['pass'][0]));
}
}
Fatal Error
Error: Call to a member function find() on a non-object
File: C:\wamp\www\blogproject\app\Model\Post.php
Line: 51
Solução
Your model name is Post not Posts so change Posts->find()
to Post->find()
.
Also for example in Post->fetch()
your are in Post model scope so use $this->find()
not $this->Post->find().
Read about cake conventions. Model names are singular.