CodeIgniter Forums
Controllers under subfolder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Controllers under subfolder (/thread-65608.html)

Pages: 1 2 3 4


RE: Controllers under subfolder - arma7x - 07-10-2016

(07-10-2016, 07:00 AM)InsiteFX Wrote: @ arma7x

I do not get your point on this because http://127.0.0.1/path/to/public Works just fine on my Windows system and has for years but now I use VirtualHosts
Yes, http://127.0.0.1/path/to/public work fine. But if you using url helper, the base_url return http://127.0.0.1/ instead of http://127.0.0.1/path/to/public


RE: Controllers under subfolder - InsiteFX - 07-10-2016

Strange I never saw that, but anyways I use VirtualHosts now a lot nicer.


RE: Controllers under subfolder - ibraheem_ghazi - 07-25-2016

so as i understand to make a controller in sub folder
i should set the namespace for each one of them to be like

namespace App\Controllers\SubFolder;

what if i need to change the SubFolder name then i should enter each file and edit namespace ??
i see that it would be much better if it depend on one of them either namespace or folder name


RE: Controllers under subfolder - mwhitney - 07-27-2016

(07-25-2016, 07:42 PM)ibraheem_ghazi Wrote: so as i understand to make a controller in sub folder
i should set the namespace for each one of them to be like

namespace App\Controllers\SubFolder;

what if i need to change the SubFolder name then i should enter each file and edit namespace ??
i see that it would be much better if it depend on one of them either namespace or folder name

You could change the directory name without changing the namespaces, but that would involve editing the autoload configuration, and would make it more difficult to find those controllers later.


RE: Controllers under subfolder - andybiancoblu - 09-26-2019

(07-05-2016, 08:42 PM)kilishan Wrote: Thanks to this thread I have identified a couple of issues with the Routing. In part, was my original assumptions turned out incorrect - I thought the two philosophies would be used separately. Either you had a namespaced controller that was specified in the routes file, or the auto-routed version to stuff in the controller folder, where the classes were in the global namespace.

Listening to your feedback, I've gone back and fixed one issue that was keeping non-namespaced controllers from being auto-routed last night. Though I'm trying to find a nice way to make it testable currently. Smile And I will be working on making auto-routing working with namespaces - as long as that namespace lands in the controllers folder, anyway.

So - thanks for the feedback! And, have patience, we'll work the bugs out. Smile
Hi everyone.
I've been looking for help also in another thread (https://forum.codeigniter.com/thread-73262.html) but no one could help me.

So...
I downloaded CI4 and installed it in a docker container with php7.2.1 and set up an apache2 virtualhost with mod_rewrite enabled. Htaccess works fine.

I decided to try sub folders separation for my controllers according to documentation: https://codeigniter4.github.io/CodeIgniter4/incoming/controllers.html#organizing-your-controllers-into-sub-directories

Namespaced my controllers with App/Controllers/subfoldername
Tried accessing with the url myenv.local/subfioldername/controllername/method


Always geting a 404 error saying:

404 - File Not Found

Controller or its method is not found: {0}::{1}

Am I missing something?
Do I need to map with $routes->add every single class and method in subfolder in the form of
PHP Code:
$routes->add('subfoldername/class''class::method', ['namespace' => 'App\Controllers\subfoldername']); 
?

Because if it is like this seems to me a little to verbose...

Thanks in advance for any help!
I'm stuck with this issue and I can't go on developing.
I love CI and love even more CI4 (I find its philosophy perfect and modern!!)
Please don'0t make me migrate on a different php framework!
Sincerely


RE: Controllers under subfolder - InsiteFX - 09-26-2019

You can use the routes group to setup your sub folders.

PHP Code:
$routes->group('', ['namespace' => 'App\Controllers\Admin'], function($routes)
{
    $routes->get('admin''Admin::index');
    $routes->get('admin/(:any)''Admin::view/$1');
}); 

Some thing like that.


RE: Controllers under subfolder - titounnes - 09-26-2019

(07-02-2016, 01:02 AM)sv3tli0 Wrote: Remember that MY_ classes existed in the old CI versions because there were no namespaces.. Now in CI 4 you are able simply to create App/Controllers/Controller and to use it from your other controllers..
The era of MY_ logic is over.
Agree....


RE: Controllers under subfolder - andybiancoblu - 09-26-2019

(09-26-2019, 03:42 AM)InsiteFX Wrote: You can use the routes group to setup your sub folders.

PHP Code:
$routes->group('', ['namespace' => 'App\Controllers\Admin'], function($routes)
{
    $routes->get('admin''Admin::index');
    $routes->get('admin/(:any)''Admin::view/$1');
}); 

Some thing like that.
@InsiteFX

That solution is ok, but why there's no mention of this in the official docs? Why other users are getting it to work withouth metioning to add such routes?
What I'm trying to understand is if it's me having a "faulty" config or "faulty" install and I need such workaround or this is just regular parctice to route to controllers located in subfolders.


RE: Controllers under subfolder - InsiteFX - 09-26-2019

I found out a lot of this by looking at Lonnie's code.

See his Myth Auth and Simple Forums for CodeIgniter 4.

It will teach you a lot about it.

Lonnie GitHub


RE: Controllers under subfolder - andybiancoblu - 09-26-2019

(09-26-2019, 04:37 AM)InsiteFX Wrote: I found out a lot of this by looking at Lonnie's code.

See his Myth Auth and Simple Forums for CodeIgniter 4.

It will teach you a lot about it.

Lonnie GitHub

Thanks a lot, I immediately looked at these projects and found them really inspiring. But again, what i don't understand is why I'm trying to use an "out of the box" feature that shouldn't require additional routing using routes->group with closure. In Lonnie CI4 forum you have folders outside Controllers folder, and so additional routing is required. But while I'm building subfolders INTO Controllers folder, I shouldn't have to remap class and methods. Otherwise it would be simplier a require_once statement.

This is driving me crazy, cause I know I already could be developing instead of losing time troubleshooting this.

Anyway, thanks a lot for your help Smile