简体   繁体   中英

CakePHP and namespaces?

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.

I don't think there is. CakePHP looks for classes like PostsController or BlogController , not foo\\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?

Why not give up the App::import() in cakephp 1.3 . Replace it with the include_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM