• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't make Dynamic Routes with Groups And Spacenames and Regex work


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 :
namespace App\Admin;
use CodeIgniter\Controller;
class Order extends Controller{
   function index(){
       echo view('admin/order_view');

What I wanted to achieve was :

$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

$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 :
$routes->get('([a-zA-Z_]+)/edit' , '$1::edit' ); 


$routes->get('([a-zA-Z_]+)/add' , '$1::add' ) 

which doesn't seem too farfetched.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.