doctrine2 zend 框架命名空间控制器
我正在尝试将doctrine2 沙箱与默认的Zend Framework 应用程序集成。当我尝试在控制器中使用命名空间时,我收到“无效的控制器类(“IndexController”)”错误
这有效:
use Entities\User, Entities\Address;
class IndexController extends Zend_Controller_Action
{
...
}
这不起作用(但应该?):
namespace Entities;
class IndexController extends \Zend_Controller_Action
{
...
}
I'm trying to integrate the doctrine2 sandbox with a default Zend Framework App. When I try to use namespacing in the controller I get an 'Invalid controller class ("IndexController")' error
This Works:
use Entities\User, Entities\Address;
class IndexController extends Zend_Controller_Action
{
...
}
This does not (but should?):
namespace Entities;
class IndexController extends \Zend_Controller_Action
{
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在第一个示例中,您将命名空间导入到控制器中。在第二个示例中,您将控制器分配给命名空间。
导入命名空间允许您引用类,而无需使用其完全限定的类名。
为控制器分配命名空间实际上会更改类的完全限定名称。
(命名空间内的类始终可以引用同一命名空间中的其他类,而不必“使用”它。我怀疑这是您尝试使用选项 2 的主要原因)。
Zend Framework 1.10 仍然对命名空间一无所知。当解析 URL 并尝试加载控制器时,它只会在默认的全局命名空间中查找
\IndexController
,并且不知道它已被分配给用户定义的命名空间 (\实体\IndexController
)。我的建议是,在 ZF 中使用控制器时,不要为它们分配命名空间。导入效果很好。我们必须等到 ZF 2.0 才能获得完整的命名空间支持。
In your first example, you are importing namespaces into the controller. In your second example, you are assigning the controller to a namespace.
Importing a namespaces allows you to reference classes without having to user their fully qualified class name.
Assigning a namespace to your controller actually changes the fully-qualified name for your class.
(Classes inside a namespace can always reference other classes in that same namespace without having to 'use' it. I suspect that was the primary reason you were trying to use option 2).
Zend Framework 1.10 is still namespace ignorant. When parsing a URL and trying to load a controller, it will look only look in the default global namespace for
\IndexController
, and have no idea that it's been assigned to a user defined namespace (\Entities\IndexController
).My recommendation is that when working with controllers in ZF, don't assign namespaces to them. Importing works fine. We'll have to wait until ZF 2.0 for full namespace support.
阅读手册并阅读一些此页面 在 PHP 中,当您想要围绕使用第二种语法的命名空间进行声明和构造。这样就会创建这样的对象
,这样 Zend 就找不到它了。
根据这些网站,您必须使用 use 来导入命名空间并使用它。
这就是为什么它在您的第一个示例中有效,而在第二个示例中无效。
希望我是对的,这会有所帮助!
After going thru the manual and reading some of this page it would seem that in PHP when you want to declare and construct around a namespace you use your second syntax. So that would create objects like
so its not found anymore by Zend.
According to those site you have to use use to import a namespace and use it.
Thats why it works in your first example and not in your second one.
Hope I am right and this helps!