开发者

zend model - no adapter found error

开发者 https://www.devze.com 2023-01-20 01:31 出处:网络
have defined different models and modelMappers in my php project. my folders are structured as follows

have defined different models and modelMappers in my php project.

my folders are structured as follows

-application
--models
---DbTable
----modelName
---modelMapperName

modelName.php
class Application_Model_DbTable_ModelName extends开发者_开发技巧 Zend_Db_Table_Abstract{

}

modelMapper.php
class Application_Model_ModelMapper
{
}

everytime i try to access the values in my database by creating an instance of my mapper in the controller i get the message No adapter found for Application_Model_DbTable_ModelName

i thought this can be an issue with the autoloader and added the following code in the bootstrap,

$loader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Application',
'basePath' => APPLICATION_PATH
));

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

return $loader;

but it still didnt work, can anyone help me figure out where i am going wrong?

thank you.


This error it's related to database initialization...

You have to configure the database adapter in your application.ini:

resources.db.adapter            = "pdo_mysql"
resources.db.params.host        = "localhost"
resources.db.params.username    = "user"
resources.db.params.password    = "password"
resources.db.params.dbname      = "db"

Or you could also configure the database adapter in your bootstrap file:

$db = Zend_Db::factory("pdo_mysql", $params);
Zend_Db_Table::setDefaultAdapter($db);


Since the variable APPLICATION_PATH returns de full path to your application folder try naming your classes only

Model_DbTable_ModelName


i found out that the variable i was trying to access didn't start with an underscore and also capitalization issues with the models created was causing the problem.

Thank you all for helping

0

精彩评论

暂无评论...
验证码 换一张
取 消