Zend 框架 1.11 +原则 2 集成:自动加载模型 models/user.php ->型号\用户
我如何设置自动加载,以便我可以拥有像这样的目录结构
/application
/models <<--- plural
...
并让 Zend/Doctrine Autoloader 加载 Application\Model\User
。注意模型是单一的。
目前,我的自动加载器设置如下(在 Bootstrap.php _initDoctrine()
中)
$zendAutoloader = Zend_Loader_Autoloader::getInstance();
// Symfony
$autoloader = array(new ClassLoader('Symfony'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Symfony\\');
// Doctrine
$autoloader = array(new ClassLoader('Doctrine'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Doctrine\\');
// Models
$autoloader = array(new ClassLoader('Application\\Model', realpath(__DIR__ . '/models')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Model');
// Proxies
$autoloader = array(new ClassLoader('Application\\Model\\Proxy', realpath(__DIR__ . '/models/proxies')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Model\\Proxy');
目前,当我尝试使用 Application\Model\User
时,我得到
require(D:\Projects\Tickle\application\models\Application\Model\User.php): 无法打开流:没有这样的文件或目录
它试图包含 application\models\应用程序\模型\User.php
。嗯,它比我预想的更奇怪。无论如何我该如何解决它?
How can I setup autoloading such that I can have my directory structure like
/application
/models <<--- plural
...
And have Zend/Doctrine Autoloader load Application\Model\User
. Notice Model is singular.
Currently I have autoloader setup as follows (in Bootstrap.php _initDoctrine()
)
$zendAutoloader = Zend_Loader_Autoloader::getInstance();
// Symfony
$autoloader = array(new ClassLoader('Symfony'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Symfony\\');
// Doctrine
$autoloader = array(new ClassLoader('Doctrine'), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Doctrine\\');
// Models
$autoloader = array(new ClassLoader('Application\\Model', realpath(__DIR__ . '/models')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Model');
// Proxies
$autoloader = array(new ClassLoader('Application\\Model\\Proxy', realpath(__DIR__ . '/models/proxies')), 'loadClass');
$zendAutoloader->pushAutoloader($autoloader, 'Application\\Model\\Proxy');
Currently, when I try using Application\Model\User
, I get
require(D:\Projects\Tickle\application\models\Application\Model\User.php): failed to open stream: No such file or directory
Its trying to include application\models\Application\Model\User.php
. hmm its wierder than I expected. How can I fix it anyways?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
我解决这个问题的方法是使用 Doctrine 的 autoloader/
ClassLoader
而不是 Zend 的第一个错误是我应该使用
realpath(__DIR__ . '/..')
使用我的目录结构,...指向“Tickle”,这样当学说附加路径“Application/Models/User.php”时,它将看起来像存在的“/Tickle/Application/Models/Users.php”
The way I resolved this was to use Doctrine's autoloader/
ClassLoader
instead of Zend's1 of my mistakes was that I should be using
realpath(__DIR__ . '/..')
which with my directory structure, ...Points to "Tickle", so that when doctrine appends the path "Application/Models/User.php" it will look like "/Tickle/Application/Models/Users.php" which exists