Hi,
I am having trouble defining my routes for my admin pages.
I have multiple Controllers in my app/Admin folder with Namespace App\Admin (including Dashboard and Order)
Here is an example Order.php :
Code:
<?php
namespace App\Admin;
use CodeIgniter\Controller;
class Order extends Controller{
function index(){
echo view('admin/order_view');
}
}
What I wanted to achieve was :
Code:
$routes->get('/', 'Home::index');
$routes->group('admin', ['namespace' => 'App\Admin'], function($routes)
{
$routes->get('/', 'Dashboard');
$routes->get('([a-zA-Z_]+)', '$1');
});
to get the default index function of my \App\Admin\Order controller.
I did notice the $0, $1 ... syntax only works when there is at least one forward slash in front of my route "/([a-zA-Z_]+)" which I think is unfortunate.
I can easily show the Dashboard (example.com/admin) that is hardcoded but can't seem to get the Order controller (example.com/admin/Order or even example.com/admin/order) through the regex, although they are in the same namespace and folder.
It seems that you can use a lower case first letter when you want to get a controller through its filename, but when it comes to namespaces it's case sensitive or am I wrong?
I also tried
Code:
$routes->get('/', 'Home::index');
$routes->group('admin', ['namespace' => 'App\Admin'], function($routes)
{
$routes->get('/', 'Dashboard');
});
$routes->get('admin/([a-zA-Z_]+)', '\App\Admin\$1');
but alas it doesn't work either. I was hoping to use the group feature so that I can easily add other routes through regex like :
Code:
$routes->get('([a-zA-Z_]+)/edit' , '$1::edit' );
or
Code:
$routes->get('([a-zA-Z_]+)/add' , '$1::add' )
which doesn't seem too farfetched.