CakePHP: organise controllers in subfolders
Asked Answered
A

4

5

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

Addend answered 12/1, 2012 at 13:48 Comment(0)
M
3

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.

Meatiness answered 12/1, 2012 at 14:2 Comment(3)
Oh, specifying additional paths! I could do that, but why deprecated? Should I use plugins instead? It's just because my website is divided into sections, each one very separated from the other ones, and I'd like to organise a bit the code (I've got a lot of files!).Addend
I actually have no idea, as this was promoted in earlier versions. Plugins seem to be the way to go.Meatiness
Discussions are not decisions and this depreciation content in the answer answer is simply not accurate.Rogers
M
9

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

Mare answered 15/8, 2013 at 6:3 Comment(0)
M
3

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.

Meatiness answered 12/1, 2012 at 14:2 Comment(3)
Oh, specifying additional paths! I could do that, but why deprecated? Should I use plugins instead? It's just because my website is divided into sections, each one very separated from the other ones, and I'd like to organise a bit the code (I've got a lot of files!).Addend
I actually have no idea, as this was promoted in earlier versions. Plugins seem to be the way to go.Meatiness
Discussions are not decisions and this depreciation content in the answer answer is simply not accurate.Rogers
R
1

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

Rogers answered 8/1, 2016 at 21:59 Comment(0)
A
0

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... ;)

Archdeaconry answered 31/1, 2016 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.