Issue with subfolder controller structure like admin folder
Closed this issue · 5 comments
Hi
Iam first time using this advanced routing system on Codeigniter..
Something like regular ci, working code: $route['admin'] = 'admin/account/login'
After login, i need open another controller which is present on Admin folder. ie., admin/Dashboard.php
i placed below code:
Route::prefix('admin', function() {
Route::get('dashboard', 'admin/dashboard/method');
});
Test URL request something like:
http://localhost/ci/admin/dashboard/
Iam getting 404errors. (i placed htaccess code also remove index.php from url)
Please can suggest where i did wrong
Hi, sorry about the delay, I was on vacation.
About your problem, this example works fine for me. So. It can be a problem with the route index.php, or that the controller's file name it's "dashboard" instead of "Dashboard", or maybe you are not calling "Route::map()" ?
If everything's okay tell me and we will see what could be the specific problem.
Also, check it without the anonymous function like
Route::any('admin/dashboard', 'admin/dashboard/method');
It could be a problem with the php version and the anonymous functions?
Hi Patroklo
Iam very sorry the delay..
Actually i have folder structure ike below
controllers/ some controllers list (frontend)
controllers/ admin/
- account
- dashboard
- employees
etc... (above 3 are in admin folder)
Now, take some scenario like, we need to show Dashboard after login.
Default codeigniter will works for the below link without placing any routes..
URL : http://localhost/ci/admin/dashboard/
Above link works fine without placing any routes on routes.php , Because both admin(folder) & dashboard (controller) exists..
($route['admin/dashboard'] = "admin/dashboard/index";) This line is not required for Default..
In the same way, is it possible with this codeigniter-static-laravel-routes library..
I mean, without placing this below line
Route::any('admin/dashboard', 'admin/dashboard/method');
This link should work: http://localhost/ci/admin/dashboard/
Reason for asking this was, need to add single link on routes.php as above line.
Is Below thing possible??
admin/ *, *, * etc...
Without breaking any links, is it possible to change Admin folder name ? ( Admin -to- sp-admin )
sp-admin/,,* -
Hi
Yes, you can make something like this
Route::any('admin/(:any)', 'admin/dashboard/$1');
And then every string in any will go to its method in Dashboard controller.
Obviously, if method doesnt exist, it will throw a error calling a method, not a 404, so its up to you to change that into a 404. I can suggest you to use a filter that detects if a method exist and if it doesnt, make a show_404();