Probleme fonction find

Par arcoss 3x, il y a 10 ans


Bonjour,
je regarde actuellement la video cake php jour 3 et j ai une erreur :

Fatal Error Error: Call to a member function find() on a non-object File: F:\wamp\www\2.7\app\Controller\PostsController.php Line: 48 Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp ( ! ) Xdebug: user triggered in F:\wamp\www\2.7\lib\Cake\View\Errors\fatal_error.ctp on line 37 Call Stack # Time Memory Function Location 1 0.0008 265448 {main}( ) ..\index.php:0 2 0.0297 2832608 Dispatcher->dispatch( ) ..\index.php:118 3 0.0444 3759024 Dispatcher->_invoke( ) ..\Dispatcher.php:167 4 0.0463 3832472 Controller->invokeAction( ) ..\Dispatcher.php:193 5 0.0463 3833024 invokeArgs ( ) ..\Controller.php:490 6 0.0463 3833176 PostsController->category( ) ..\Controller.php:490 7 0.0559 4724152 App::shutdown( ) ..\App.php:0 8 0.0563 4724984 App::_checkFatalError( ) ..\App.php:906 9 0.0563 4726200 call_user_func:{F:\wamp\www\2.7\lib\Cake\Core\App.php:933} ( ) ..\App.php:933 10 0.0563 4726424 ErrorHandler::handleError( ) ..\App.php:933 11 0.0564 4727168 ErrorHandler::handleFatalError( ) ..\ErrorHandler.php:213 12 0.0571 4730032 call_user_func:{F:\wamp\www\2.7\lib\Cake\Error\ErrorHandler.php:274} ( ) ..\ErrorHandler.php:274 13 0.0571 4730272 ErrorHandler::handleException( ) ..\ErrorHandler.php:274 14 0.0614 4897296 ExceptionRenderer->render( ) ..\ErrorHandler.php:127 15 0.0614 4898000 call_user_func_array:{F:\wamp\www\2.7\lib\Cake\Error\ExceptionRenderer.php:187} ( ) ..\ExceptionRenderer.php:187 16 0.0614 4898360 ExceptionRenderer->_cakeError( ) ..\ExceptionRenderer.php:187 17 0.0615 4901032 ExceptionRenderer->_outputMessage( ) ..\ExceptionRenderer.php:210 18 0.0615 4901560 Controller->render( ) ..\ExceptionRenderer.php:289 19 0.0752 6517072 View->render( ) ..\Controller.php:960 20 0.0758 6529288 View->_render( ) ..\View.php:473 21 0.0760 6530800 View->_evaluate( ) ..\View.php:933 22 0.0763 6560920 include( 'F:\wamp\www\2.7\lib\Cake\View\Errors\fatal_error.ctp' ) ..\View.php:971 23 0.0836 7126616 xdebug_print_function_stack ( ) ..\fatal_error.ctp:37

et voice mon PostController :

<?php class PostsController extends AppController { /** * RequestAction, permet d'avoir la liste des contenus pour le menu **/ function menu(){ $pages = $this->Post->find('all',array( 'conditions' => array('type'=>'post','online'=>1), 'fields' => array('id','slug','name') )); return $pages; } function index(){ $d['posts'] = $this->Paginate('Post',array('type'=>'post','online'=>1 )); $this->set($d); } /** * Permet d'afficher une page **/ function show($id = null,$slug = null){ if(!$id) throw new NotFoundException('Aucunes pages ne correspond � cet ID'); $page = $this->Post->find('first',array( 'conditions' => array('id' => $id,'type'=>'post') )); if(empty($page)) throw new NotFoundException('Aucunes pages ne correspond � cet ID'); if($slug != $page['Post']['slug']) $this->redirect($page['Post']['link'],301); $d['page'] = current($page); $this->set($d); } /** * **/ function admin_index(){ $d['posts'] = $this->Paginate('Post',array('type'=>'post','online >= 0')); $this->set($d); } function category($category){ $this->loadModel('Caterory'); $cat = $this->Category->find('first',array( 'conditions' => array('slug' => $category) )); if(empty($cat)) throw new NotFoundException('Aucunes cat�gorie ne correspond � cet ID'); $d['posts'] = $this->Paginate('Post',array('type'=>'post','online >= 0','category_id' => $cat['Category']['id'])); $this->set($d); $this->render('index'); } function admin_edit($id = null){ if($this->request->is('put') || $this->request->is('post')){ if($this->Post->save($this->request->data)){ $this->Session->setFlash("L'article a bien �t� modifi�","notif"); $this->redirect(array('action'=>'index')); } }elseif($id){ $this->Post->id = $id; $this->request->data = $this->Post->read(); }else{ $this->request->data = $this->Post->getDraft('post'); } $this->loadModel('Category'); $d['categories'] = $this->Category->find('list'); $this->set($d); } function admin_delete($id){ $this->Session->setFlash('La page a bien �t� supprim�e','notif'); $this->Post->delete($id); $this->redirect($this->referer()); } }

Merci d avance :)

2 réponses

Lartak, il y a 10 ans

Bonsoir.
Je suppose que ça concerne la function category, si c'est le cas c'est normal, puisque tu fais un $this->loadModel de Caterory au lieu de Category.
En tout cas, le numéro de la ligne correspond à celui de la ligne retournée par l'erreur de CakePHP.

arcoss 3x, il y a 10 ans

merci ca marche