izniburak / php-router

PHP Router, which also has rich features like Middlewares and Controllers is simple, useful and flexible router class for PHP.
https://github.com/izniburak/php-router/wiki
MIT License
238 stars 45 forks source link

Use Subfolders in Controllers Folders #78

Open chrisasek opened 2 weeks ago

chrisasek commented 2 weeks ago

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

izniburak commented 2 weeks ago

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

chrisasek commented 2 weeks ago

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.

izniburak commented 2 weeks ago

Could you please share your directory structure and routing definition?

chrisasek commented 2 weeks ago
Screenshot 2024-11-06 222851

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

izniburak commented 2 weeks ago

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.

chrisasek commented 2 weeks ago

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
izniburak commented 2 weeks ago

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.

chrisasek commented 1 week ago

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