Zend Framework:在 config.ini 中自动加载模块资源?
是否可以在 application.ini 中配置以下行为?
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAdminModuleAutoloader()
{
$this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Admin',
'basePath' => APPLICATION_PATH . '/modules/admin',
));
$this->_resourceLoader->addResourceTypes(array(
'model' => array(
'namespace' => 'Model',
'path' => 'models'
)
));
}
}
?>
如果是这样,您能给我们举个例子吗?
谢谢。
Is it possible, to configure the following behaviour in application.ini?
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAdminModuleAutoloader()
{
$this->_resourceLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Admin',
'basePath' => APPLICATION_PATH . '/modules/admin',
));
$this->_resourceLoader->addResourceTypes(array(
'model' => array(
'namespace' => 'Model',
'path' => 'models'
)
));
}
}
?>
If so, can you please show us an example?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些提示。首先,您的 application.ini 文件中应包含以下行。
这将确保 Zend_Application_Resource_Modules 中的以下函数运行
在上面的函数中,您的模块引导程序被调用。您需要在 /application/modules/admin 中有一个名为 Bootstrap.php 的模块引导文件,其中包含以下代码:
我将跳过几个步骤,但如果您跟踪继承类,这将导致以下函数在 Zend_Application_Module_Autoloader 中调用
对于您遵循此模式的每个模块,默认情况下将涵盖所有上述资源类型。您需要的任何其他内容都需要在引导文件中进行自定义。
Here are a couple of pointers. First you should have the below line in your application.ini file.
That will make sure that the following function in Zend_Application_Resource_Modules runs
In the above function your module bootstrap is called. You need to have a module bootstrap file in /application/modules/admin called Bootstrap.php with the following code in it:
I'm going to skip a few steps but if you trace through the inheritance classes this will lead to the following function being called in Zend_Application_Module_Autoloader
All of the above resource types will be covered by default for every module that you follow this pattern for. Any others that you need will need to be customized in a bootstrap file.
我使用 Zend Framework 版本 1.10.4 和默认项目配置。我使用以下行激活 application.ini 中的所有模块:
模块目录中有一个 Bootstrap.php 很重要。如果没有它,我的模型就无法正确加载。您的浏览器中的 URL 似乎区分大小写。例如: http://example.com/Admin/controller/action
所以,它应该工作...
I am using Zend Framework Version 1.10.4 with a default project configuration. I activate all Modules in my application.ini with the following line:
Its important that you have a Bootstrap.php in your module directory. Without that, my models wasn't loaded correctly. The URL in your Browser seems to be case sensitive. For example: http://example.com/Admin/controller/action
So, it should work...