Zend Framework 从 Application/Model/ 而不是 application/models 加载映射器
我的 zend 应用程序已创建,一切似乎都按顺序进行,但每次我尝试执行以下操作时:
$accProducts = new Application_Models_AccProductsMapper();
只得到:
警告:include_once(Application / Models / AccProductsMapper.php):无法打开流:第148行的/home/blah/blah/blah/Loader.php中没有这样的文件或目录
但是,AccProductsMapper.php文件确实如此存在于这样的目录中,zend应用程序内的目录都是小写的。
我花了很多时间寻找解决这个问题的方法,但没有任何好的结果。
Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace(array('App','My_'));
return $moduleLoader;
}
}
My zend app is created, everything seems to be in order but every time I try to do something like:
$accProducts = new Application_Models_AccProductsMapper();
Only get:
Warning: include_once(Application/Models/AccProductsMapper.php): failed to open stream: No such file or directory in /home/blah/blah/blah/Loader.php on line 148
however, the AccProductsMapper.php file do exist in such directory, directories within the zend app are all lowercase tough.
I've spend a lot of time looking for something to solve this issue with no good results at all.
Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctype()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype('XHTML1_STRICT');
}
protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace(array('App','My_'));
return $moduleLoader;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加到每个模块的标准
Zend_Loader_Autoloader_Resource
类在/models
中查找具有类前缀_Model_
的模型。对于默认模块,命名空间在配置的
appnamespace
属性中定义(默认为Application
)。该目录通常是application
。总而言之,在
application/models
中使用类前缀Application_Model_
创建默认模块模型类,例如至于您的
_initAutoload()
方法,我可以不告诉您正在使用该模块加载器做什么,并会建议您根本不需要它。您可以在配置文件中注册 PEAR 风格的命名空间,例如The standard
Zend_Loader_Autoloader_Resource
class added to each module looks for models with the class prefix<ModuleNamespace>_Model_
in<module-directory>/models
.For the default module, the namespace is defined in your config's
appnamespace
property (defaults toApplication
). The directory is typicallyapplication
.To summarize, create your default module model classes in
application/models
with class prefixApplication_Model_
, egAs for your
_initAutoload()
method, I can't tell what you're doing with that module loader and would advise you don't need it at all. You can register PEAR style namespaces in your config file, eg