CodeIgniter Route example

its more fancy looked url

http://your.co/portfolio/portfolio-categories-nature/

http://your.co/portfolio/portfolio-categories-nature/pic-from-bromo-mountain

than this

http://your.co/portfolio/gallery/portfolio-categories-nature/

http://your.co/portfolio/detail/portfolio-categories-nature/pic-from-bromo-mountain

how you can doing this, if the controllers


 

<?php

# controllers/portfolio.php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class portfolio extends CI_Controller {

public function __construct(){

parent::__construct();
}
public function index(){
echo "hello index";
}

public function gallery($input){
echo "@gallery ".$input;
}

public function detail($input1,$input2){
echo "@detail ".$input1.' and '.$input2;
}
}

and that is why you need route in codeigniter


<?php

# config/route.php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['portfolio'] = "portfolio/index";
$route['portfolio/(:any)/(:any)'] = "portfolio/detail/$1/$2";
$route['portfolio/(:any)'] = "portfolio/gallery/$1";

 

ci-routes-hasil-routes

Published by

G3n1k

just to remember what i had known :)

One thought on “CodeIgniter Route example”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s