Welcome Guest, Not a member yet? Register   Sign In
Question about routes
#1

[eluser]Unknown[/eluser]
Hello there,

I´m new to this forum. I´m not an experienced user of Code Igniter. There is a gallery on my site. I´m using one-to-one relationship between a URL string and its corresponding controller class/method. For example, http://www.mywebsite.com/gallery/2013-1. Can somebody tell me how can I do sometning like this: http://www.mywebsite.com/gallery/2013/1?

I´m sorry for my bad English, but this is not my born language.
#2

[eluser]ivantcholakov[/eluser]
Within application/config/routes.php add:
Code:
$route['gallery/(:num)/(:num)'] = 'gallery/index/$1/$2';
// A more general rule, if it is needed:
//$route['([a-zA-Z_-]+)/(:num)/(:num)'] = '$1/index/$2/$3';

Within your gallery controller put the following for testing:
Code:
// This gives an idea how to retrieve the necessary parameters.
echo $this->uri->rsegment(1).'/'.$this->uri->rsegment(2).'/'.$this->uri->rsegment(3).'/'.$this->uri->rsegment(4);

This is the approach job to be done, maybe I am not precise for your particular case.
#3

[eluser]CroNiX[/eluser]
@ivantcholakov - you can also retrieve them as parameters to your function.

Code:
$route['gallery/(:num)/(:num)'] = 'gallery/view/$1/$2';

Code:
class Gallery extends CI_Controller {

  function view($param1 = null, $param2 = null)
  {
    //$param1 = $1 from route, or null if nothing present
    //$param2 = $2 from route, or null if nothing present
  }
}
#4

[eluser]ivantcholakov[/eluser]
@CroNiX

Yes, you are right. I avoid this way, because on my highly customized platform it seems to be not working. On a clean CodeIgniter it should work.




Theme © iAndrew 2016 - Forum software by © MyBB