php-router icon indicating copy to clipboard operation
php-router copied to clipboard

Use Subfolders in Controllers Folders

Open chrisasek opened this issue 1 year ago • 8 comments

I want to use sub-folders inside the Controllers folders.

chrisasek avatar Nov 06 '24 17:11 chrisasek

Hi @chrisasek , You can. Please check the documentation: https://github.com/izniburak/php-router/wiki/5.-Controllers#basic-usage

izniburak avatar Nov 06 '24 17:11 izniburak

In the documentation you can set the path for the controllers.

If I set the path as app/controllers for example and I want to have a folder let's say 'user' for all the user controllers.

When I load a controller from the user folder inside the set controllers folder, I throw an error.

chrisasek avatar Nov 06 '24 19:11 chrisasek

Could you please share your directory structure and routing definition?

izniburak avatar Nov 06 '24 21:11 izniburak

Screenshot 2024-11-06 222851

Controllers from the admin folder or admin aren't working.

chrisasek avatar Nov 06 '24 21:11 chrisasek

I don't see any problem about the folder structure. Are you sure about the namespaces of the controllers in subfolder? Also, what is the APP_URL constant value? base_folder option of the Router config should be folder name of the folder that the project run in.

BTW, I use similar structure on a project, I have no any issue. Probably, you have an configuration or definition issue.

izniburak avatar Nov 08 '24 17:11 izniburak

I have double check on my end, the namespaces are same and the base_folder is the root of the project like you mentioned.

I checked the resolveClassName function in Router.php on line 668, it doesn't account for subfolder in the controller set path.

What do you think?

Controller Path

chrisasek avatar Nov 08 '24 19:11 chrisasek

How do you use your controllers that defined in subfolder when add a new router? Can you share your related routing definition? I try to reproduce your flow in my local.

BTW, this project is public in Github? Maybe I can check the issue detailed.

izniburak avatar Nov 08 '24 20:11 izniburak

I just added a public project for you to check the issue: https://github.com/chrisasek/Dicer-mvc

chrisasek avatar Nov 14 '24 12:11 chrisasek