CakePHP 和命名空间?
有没有办法使用 cakephp 将自己的代码放入命名空间中?以下非常简单的控制器类工作正常。
class Customer extends \AppModel {
var $name = 'Customer';
}
但是,如果我添加
namespace foo\bar;
cakephp 就找不到控制器了。有没有什么方法可以告诉 cake 应该在哪个命名空间中寻找控制器?
我正在使用 cakephp 1.3 和 php 5.3。
Is there a way to put your own code into namespaces using cakephp? The following very simple controller class works fine.
class Customer extends \AppModel {
var $name = 'Customer';
}
However, if I add
namespace foo\bar;
cakephp can't find the controller anymore. Is there some way to tell cake in which namespace it should look for controllers?
I am using cakephp 1.3 and php 5.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为不存在。 CakePHP 查找诸如
PostsController
或BlogController
之类的类,而不是foo\bar\PostsController
。也许您可以告诉 CakePHP 在哪个文件夹中查找这些类(可能),但它仍然会查找未命名的类名。为什么要在不使用名称空间的框架中使用它?
I don't think there is. CakePHP looks for classes like
PostsController
orBlogController
, notfoo\bar\PostsController
. Maybe you can tell CakePHP in what folder to look for those classes (probably), but then it will still be looking for unnamepsaced class names.Why would you want this in a framework that doesn't use namespaces?
为什么不放弃 cakephp 1.3 中的
App::import()
呢?将其替换为include_once()
。我在命名空间下定义了自定义供应商类,效果很好。只是为了防止自定义类名与官方类名冲突。
Why not give up the
App::import()
in cakephp 1.3. Replace it with theinclude_once()
.I got my customize vendor classes defined under a namespace works fine. Just to prevent the collision of the custom class name with the official one.