Welcome Guest, Not a member yet? Register   Sign In
Controllers under subfolder
#21

(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
Keep calm.
Reply
#22

Strange I never saw that, but anyways I use VirtualHosts now a lot nicer.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#23

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
Reply
#24

(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.
Reply
#25

(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/CodeIgnit...irectories

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
[Image: https://vulndetect.org/assets/uploads/fi...docker.ico]

Andy Biancoblu 

Quote:Once you have eliminated the impossible, whatever remains, however improbable, must be the truth.
Reply
#26

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#27

(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....
Reply
#28

(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.
[Image: https://vulndetect.org/assets/uploads/fi...docker.ico]

Andy Biancoblu 

Quote:Once you have eliminated the impossible, whatever remains, however improbable, must be the truth.
Reply
#29

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#30

(This post was last modified: 09-26-2019, 04:54 AM by andybiancoblu.)

(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
[Image: https://vulndetect.org/assets/uploads/fi...docker.ico]

Andy Biancoblu 

Quote:Once you have eliminated the impossible, whatever remains, however improbable, must be the truth.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB