CakePHP: organise controllers in subfolders

喜你入骨 提交于 2019-12-10 14:22:31

问题


Is it possible in CakePHP to organise controllers (and models) in subfolders? Thanks.


回答1:


Yes you can, but it is deprecated. See the discussion here. The last post on this page describes how to do it in the bootstrap.




回答2:


It's not deprecated at all. You can accomplish this using the App:build and point to your subfolders. For example, if you want to put all of your Twitter models in Model/Twitter to keep your code organized, you can add the following to the bootstrap.php:

App::build(array(
    'Model' => array(APP . 'Model' . DS . 'Twitter' . DS),
));

Now, any model file you put in Model/Twitter will be available when you call it.

See more here: http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#App::build




回答3:


For those of you looking for a CakePhp3 version of this answer here is a link to the routing documentation. Use router prefixing that matches your controller sub-namespaces / directory structure.

http://book.cakephp.org/3.0/en/development/routing.html#prefix-routing




回答4:


In CakePHP 3 you can define additional class paths in your composer.json (see http://book.cakephp.org/3.0/en/development/configuration.html#additional-class-paths)

Btw if you want to organize your template files in subfolders you have to add their paths in your app.php at App.paths http://book.cakephp.org/3.0/en/development/configuration.html#general-configuration

Just in case someone else is searching for this piece of information... ;)



来源:https://stackoverflow.com/questions/8836128/cakephp-organise-controllers-in-subfolders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!