Hi,

Thanks for the help, Matt, I really appreciate it. However, I'm at a loss as
to what could be going on, as adding the autoloader code to my default
module bootstrap as you describe below is precisely what what I've done. To
recap:


Matthew Weier O'Phinney-3 wrote:
> 
>  * In your default module's bootstrap, initialize an autoloader:
>  
>        protected function _initDefaultAutoloader()
>        {
>            $al = new Zend_Application_Module_Autoloader(array(
>                'namespace' => 'Default', // or 'App', or whatever
>                'basePath'  => dirname(__FILE__),
>            ));
>            return $al;
>        }
> --snip--
> Once autoloading is complete, if your models are in the appropriate
> directory and named correctly:
> 
>     models/
>         Foo.php - Default_Model_Foo
> 
> then you can simply instantiate them and use them:
> 
>     $foo = new Default_Model_Foo();
> 

In an attempt to figure out what was happening, I created a brand new
project named zftest (using Zend_Tool). I then created a module named admin
using the command:

zf create module admin

I then modified my application.ini file, adding the following two lines:

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

I created a controller/view, placing it in the admin module's controllers
directory. I tested it in the browser and everything works fine. I then
created the following model, saving it in the default models directory as
Category.php:

class Default_Model_Category extends Zend_Db_Table
{       
}

I added the usual db connection lines to application.ini, attaching the
application to an existing MySQL database which contains a table named
category. I then made the following call in my default module's
IndexController:

$category = new Default_Model_Category();

Calling the index controller in the browser, everything worked fine. The
trouble begins when I add the very same command to a controller found in the
admin module. When I attempt to call that controller from the browser, I
receive the following stack trace:

 Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table
'zftest_dev.default_model_category' doesn't exist
Stack trace:

#0 C:\apache\htdocs\zftest\library\Zend\Db\Statement.php(284):
Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\apache\htdocs\zftest\library\Zend\Db\Adapter\Abstract.php(468):
Zend_Db_Statement->execute(Array)
#2 C:\apache\htdocs\zftest\library\Zend\Db\Adapter\Pdo\Abstract.php(238):
Zend_Db_Adapter_Abstract->query('DESCRIBE `Defau...', Array)
#3 C:\apache\htdocs\zftest\library\Zend\Db\Adapter\Pdo\Mysql.php(156):
Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `Defau...')
#4 C:\apache\htdocs\zftest\library\Zend\Db\Table\Abstract.php(815):
Zend_Db_Adapter_Pdo_Mysql->describeTable('Default_Model_C...', NULL)
#5 C:\apache\htdocs\zftest\library\Zend\Db\Table\Abstract.php(858):
Zend_Db_Table_Abstract->_setupMetadata()
#6 C:\apache\htdocs\zftest\library\Zend\Db\Table\Abstract.php(1016):
Zend_Db_Table_Abstract->_setupPrimaryKey()
#7
C:\apache\htdocs\zftest\application\modules\admin\controllers\CategoryController.php(37):
Zend_Db_Table_Abstract->insert(Array)
#8 C:\apache\htdocs\zftest\library\Zend\Controller\Action.php(513):
Admin_CategoryController->addAction()
#9
C:\apache\htdocs\zftest\library\Zend\Controller\Dispatcher\Standard.php(289):
Zend_Controller_Action->dispatch('addAction')
#10 C:\apache\htdocs\zftest\library\Zend\Controller\Front.php(946):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#11
C:\apache\htdocs\zftest\library\Zend\Application\Bootstrap\Bootstrap.php(77):
Zend_Controller_Front->dispatch()
#12 C:\apache\htdocs\zftest\library\Zend\Application.php(346):
Zend_Application_Bootstrap_Bootstrap->run()
#13 C:\apache\htdocs\zftest\public\index.php(26): Zend_Application->run()
#14 {main}  

It strikes me as odd that ZF is attempting to execute a DESCRIBE on
Default_Model_Category? Shouldn't it have stripped Default_Model from the
name and be using the actual table name?

Any ideas? BTW I'm running ZF 1.9.2 on Windows XP.

Jason

-- 
View this message in context: 
http://www.nabble.com/Using-Default-Models-within-Other-Modules-tp25244043p25260507.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to