Stephenalistoun wrote:
>
> Hey All,
>
> I'am trying to call a Module from the Controller and I'm keep on getting
> an error stated below:
>
> Class 'Default_Module_UsersTable' not found in
> C:\wamp\www\ZendCasts\application\controllers\IndexController.php on line
> 16
>
> //***********************
> //*******Index Controller******
> //***********************
> class IndexController extends Zend_Controller_Action
> {
> public function indexAction()
> {
> $this->view->headTitle('Title - ' , 'PREPEND');
>
> $users = new Default_Module_UsersTable();
> }
> }
> //***********************
> //*******Module*******
> //***********************
> //require_once 'Zend/Db/Table/Abstract.php';
> class Default_Module_UsersTable extends Zend_Db_Table_Abstract
> {
> /**
> * The default table name
> */
> protected $_name = 'users';
>
> /*public function NewUser()
> {
> $params = array(
> 'name' => 'jane doe',
> 'email' => '[email protected]');
> //$this->users->insert($params);
> }*/
> }
> //***********************
> //*******Boot Strap*******
> //***********************
> class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
> {
> /**
> * Bootstrap autoloader for application resources
> *
> * @return Zend_Application_Module_Autoloader
> */
> protected function _initAutoload()
> {
> $autoloader = new Zend_Application_Module_Autoloader(array(
> 'namespace' => 'Default',
> 'basePath' => dirname(__FILE__),
> ));
> return $autoloader;
> }
>
> /**
> * Bootstrap the view doctype
> *
> * @return void
> */
> protected function _initDoctype()
> {
> $this->bootstrap('view');
> $view = $this->getResource('view');
> $view->doctype('XHTML1_STRICT');
> //$view->addHelperPath('App/View/Helper' , 'App_View_Helper');
> }
> }
>
>
Try this in _initAutoload (this is forfForms also) in main bootstrap:
$resourceAutoloader = new Zend_Loader_Autoloader_Resource( array(
'basePath' => realpath(dirname(__FILE__)),
'namespace' => '', // 'Default' if you have
resources.frontcontroller.params.prefixDefaultModule = true
'resourceTypes' => array(
'form' => array(
'path' => 'forms',
'namespace' => 'Form',
),
'model' => array(
'path' => 'models',
'namespace' => 'Model'
)
)
));
If you have Models in each module, put the following code in each module's
bootstrap's _initAutoload:
$resourceAutoloader = new Zend_Loader_Autoloader_Resource( array(
'basePath' => realpath(dirname(__FILE__)),
'namespace' => $modulename,
'resourceTypes' => array(
'form' => array(
'path' => 'forms',
'namespace' => 'Form',
),
'model' => array(
'path' => 'models',
'namespace' => 'Model'
)
)
));
The model name should be Default_Model_UsersTable (not Module, module is
Default in your case)
Also, if you do not have set
resources.frontcontroller.params.prefixDefaultModule = true, your model
should have no Default in its name (i.e. Model_UsersTable).
Same goes for forms - Form_Login.
Hope it helps. :-) It took me a while to figure it out...
--
View this message in context:
http://n4.nabble.com/Zend-Modules-Calling-a-Module-from-Controller-tp663625p679472.html
Sent from the Zend Framework mailing list archive at Nabble.com.