Skip to content

MisterGeorge/Dynamic-Routes

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Dynamic Routes for CodeIgniter 3.*

Generate Dynamic Routes to Codeigniter into Controllers

Requirements

  • php-5.* or php-7.*
  • FrameWork CodeIgniter 3.*
  • linux or sh command

Install

  • Download DynamicRoutes.php into libraries/
  • Download dynamicRoutes (sh) into path framework
  • Edit file config/routes.php
include_once APPPATH .'/libraries/DynamicRoutes.php';
$DynamicRoutes = new DynamicRoutes([
	'format' => 'json'
]);
$route = array_merge( $route, $DynamicRoutes->current_routes );
  • Config dynamicRoutes

Remember! that you change the comment after a route only run the following in console

  php dynamicRoutes

Examples

route controller + function

/**
 * @route:example-route
 */
class Example1 extends CI_Controller
{
  /**
 * @route:product/(:num)
 * @route:product
 */
  function product( $parm ){
    //url1: /example-route/product/1
    //url2: /example-route/product
  }
}

route on function

class Example2 extends CI_Controller
{
  /**
 * @route:hello-world
 */
  function hello_world(  ){
    //url: /hello-world
  }
  
 /**
 * @route:hi-moon
 */
  function hello_moon(  ){
    //url: /hi-moon
  }
}

arguments num and any

/**
 * @route:arguments
 */
class Example3 extends CI_Controller
{
  /**
 * @route:numeric-values/(:num)/(:num)
 */
  function numeric( $a , $b ){
    //url: /arguments/numeric-values/$1/$2
  }
  
 /**
 * @route:any-values/(:any)
 */
  function any( $a ){
    //url: /arguments/any-values/$1
  }
  
  /**
 * @route:several/(:num)/(:num)/(:any)/(:any)
 */
  function several( $a, $b , $c, $d  ){
    //url: /arguments/several/$1/$2/$3/$4
  }
}

Include method get, post, put, delete

/**
 * @route:example4
 */
class Example4 extends CI_Controller
{
  /**
  * @route:{post}data_post
  */
  function data_post(){
    //url: example4/data_post/  method = post
  }
  
 /**
  * @route:{get}my_data_get
  */
  function my_data_get(){
    //url: /example4/my_data_get/ method = get
  }
}

About

Generate routes to Codeigniter framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%