• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routes with regex and namespace

#1
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 :

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 :

PHP 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

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

or

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

which doesn't seem too farfetched.
Reply

#2
Any help resolving this issue would be greatly appreciated.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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