ZendFramework 2.0 Php Fatal Error: Uncaught Error: Class not found -


i saw few questions in direction none helped in case.

php fatal error: uncaught error: class 'booklist\model\booktable' not found in /var/www/html/module/booklist/module.php:40\

this error extracted /var/log/apache2/error.log.

i looked people same questions not find solution. included file , namespace apparently cant access file.

i'm working zenframework 2.2.10.

this how file structure looks:

module  -application -booklist    -config       \module.config.php    -src      -booklist         -controller            \bookcontroller.php         -form            \bookform.php         -model            \book.php            \booktable.php    -view       -book-list          -book             \..    \autoload_classmap.php    \module.php 

first module.php:

namespace booklist;  use zend\db\resultset\resultset; use zend\db\tablegateway\tablegateway;  use booklist\model\booktable; use booklist\model\book;  class module{     public function getautoloaderconfig()     {         return array(             'zend\loader\classmapautoloader' => array(                 __dir__ . '/autoload_classmap.php',             ),             'zend\loader\standardautoloader' => array(                 'namespaces' => array(                     __namespace__ => __dir__ . '/src/' . __namespace__,                 ),             ),         );     }      public function getconfig()     {         return include __dir__ . '/config/module.config.php';     }     public function getserviceconfig(){         return array(             'factories' => array(                 'booklist\model\booktable' => function($sm){                     $tablegateway = $sm->get('booktablegateway');                     $table = new booktable($tablegateway);                      return $table;                 },                 'booktablegateway' => function($sm) {                     $dbadapter = $sm->get('zend\db\adapter\adapter');                     $resultsetprototype = new resultset();                     $resultsetprototype->setarrayobjectprototype(new  book());                     return new  tablegateway('book',$dbadapter,null,$resultsetprototype);                 },             ),         );     } } 

this booktable.php:

namespace booklist\model;  use zend\db\tablegateway\tablegateway;  class booktable {     protected $tablegateway;      public function __construct(tablegateway $tablegateway)     {         $this->tablegateway = $tablegateway;     }     public function fetchall(){         $resultset = $this->tablegateway->select();         return $resultset;     }     public function getbook($id) {         $id = (int) $id;         $rowset = $this->tablegateway->select(array('id'=>$id));         $row = $rowset->current();         if(!$row) {             throw new \exception("could not find row $id");         }         return $row;     }     public function savebook(book $book){         $data = array(             'title' => $book->title,             'author' => $book->author,         );          $id = (int) $book->id;         if($id == 0){             $this->tablegateway->insert($data);         }else{             if($this->getbook($id)){                 $this->tablegateway->update($data,array('id'=>$id));             }             else{                 throw new \exception("book id not exist");             }         }     }     public function deletebook($id){         $this->tablegateway->delete(array('id'=>(int) $id));     }  } 

and finally, bookcontroller.php:

namespace booklist\controller; use booklist\model\book;  use booklist\form\bookform; use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel;  class bookcontroller extends abstractactioncontroller{     protected $booktable;      public function indexaction()     {         return new viewmodel(array(             'books' => $this->getbooktable()->fetchall(),         ));     }     public function addaction()     {         $form = new bookform();         $form->get('submit')->setvalue('add');          $request = $this->getrequest();         if($request->ispost()){          }         return array('form'=>$form);     }      public function editaction()     {         $form = new bookform();         //$book->bind($book);         $form->get('submit')->setattribute('value','edit');         $request = $this->getrequest();         if($request->ispost()){          }         return array(             'id' => $id,             'form' => $form,         );     }      public function deleteaction()     {         $id = (int) $this->params()->fromroute('id',0);         if(!$id){             return $this->redirect()->toroute('book');         }          $request = $this->getrequest();         if($request -> ispost()){          }         return array(             'id' => $id,             //'book' => ,         );     }     public function getbooktable(){         if(!$this->booktable){             $sm = $this->getservicelocator();             $this->booktable = $sm->get('booklist\model\booktable');         }         return $this->booktable;     } } 

the error causes when trying call class:

$table = new booktable($tablegateway); 

maybe here got idea do.

in module.php:

use booklist\model\booktable; 

should be:

use booklist\model\booktable; 

(note capital 'l').


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -