Welcome Guest, Not a member yet? Register   Sign In
Advanced admin panel routes?
#1

[eluser]Unknown[/eluser]
Hello.
I have this problem with the routes in my Codeignitor project.
So I have the folder like this.
application
-controller
-view
-admin
- groups
- Calendar

So I want my URL structure to be like: "domain.com/admin/controller/function"
How do I do this in the router config?
I also want to be able to parse a parameter like a number.
Like this: "domain.com/admin/controller/function/number"
Or in a more human way: "domain.com/admin/groups/edit/1"
#2

[eluser]morgs[/eluser]
As far as I understand, in Codeignter after the domainname.com/isthecontrollername so:
-controller
-view
-admin
- groups
- Calendar

Becomes: domain.com/admin/function/1 and not: domain.com/admin/controller/function/1.

Here's how domain.com/admin/function/1 would look like in your /application/config/routs.php:
Code:
$route[ 'admin/(:any)/(:any)' ] = 'admin/$1/$2'; // $1=Function name, $2=Parameter

Here's how your controller would look like:
Code:
if ( !defined( 'BASEPATH' ) )
{
      exit( 'No direct script access allowed' );
}

class Admin extends CI_Controller
{
       public function functionname( $number = NULL )
       {
             if ( !is_null( $number ) )
             {
                    // Parameter was passed, check if correct interger
             }
       }
}

Regards,
Morgs




Theme © iAndrew 2016 - Forum software by © MyBB