Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support controller in subdirectory #787

Closed
swordream opened this issue Aug 21, 2013 · 9 comments
Closed

Support controller in subdirectory #787

swordream opened this issue Aug 21, 2013 · 9 comments

Comments

@swordream
Copy link

In 1.1,it support controller like:

/modules/yyy/controllers/xxxx/DefaultController.php

the route is r=yyy/xxx/default/index

it seems 2.0 doesn't support this

@samdark
Copy link
Member

samdark commented Aug 21, 2013

What's the use case for it?

@swordream
Copy link
Author

a self contained modules including frontend part and backend part
for example, an article module's structre may be:
modules/article/controllers/AccountController implments register,login,logout
modules/article/controllers/admin/AccountController implements create,delete, and it can be used by admin modules or backend applicaton

@qiangxue
Copy link
Member

We dropped the support for using subdirectories in controllers folder, as it is not commonly used, and when it is needed, you can use sub-modules to achieve similar effect.

@swordream
Copy link
Author

i think sub-modules and sub-directory is two different ways to classify controllers,and in most cases it's better than submodules , beacause it is more lightweight and simple.

@qiangxue
Copy link
Member

Yes, they're different things. One of the main reasons we dropped sub-directory of controllers support is for simplicity. For example, given a route admin/post/create, can you tell the actual controller class file immediately?

Using subdirectory is a bit more lightweight, but not necessarily simpler, especially when you are also using modules.

@swordream
Copy link
Author

Complexity left to framework itself, Simplicity left to the users.
I think the module developers will know very well where actual controller class ,and to end users ,it's not important that where is actual controller class file.
BTW:framwork should should provide a variety of choice,and how to use left to the developers

@jabbon
Copy link

jabbon commented Aug 23, 2013

I think both solutions are great. Personally I use subfolder instead of sub-module when a sub-module only has one controller and when I need two o more controllers I create a sub-module.

If we could have both solutions would be amazing,

@rawtaz
Copy link
Contributor

rawtaz commented Aug 23, 2013

I stopped using subfolders for my controllers when I got fet up with having to create URL rules just to make e.g. /admin work (where admin is the subfolder name). I think it is way cleaner to use modules, and it's just one small module folder and class file away.

@santilin
Copy link
Contributor

I would be very pleased if the docs reflected this lack of support,

https://www.yiiframework.com/doc/guide/2.0/en/structure-controllers#controller-ids

I have developed an application with lots of controllers under and admin subdir only to find that it is not supported and now I have to refactor everything to a module.
It would have save me a lot of time to read that there is limited support, and that, for example, urls like:

/admin/user/update/1

won't work and you have to use

/admin/user/update?id=1

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants