Welcome Guest, Not a member yet? Register   Sign In
[HELP]URI routing question
#1

[eluser]fanxuan[/eluser]
Glad to be here. I am new to CI.

my routes config is like this :
Code:
$route['user/(:any)/blog/(:num)/'] = "user/blog/$1/$2";

my controller is like this :
Code:
class User extends Controller {
function User()
{
  parent::Controller();
  $this->load->helper('url');
}

function blog()
{
  $user=trim($this->uri->segment(3, 0));
  $id = intval($this->uri->segment(4, 0));
  echo "user";var_dump($user);
  echo "id";var_dump($id);
  //$this->load->view('welcome_message');
}
}

Now I wanna direct the url "http://localhost/blog/index.php/user/fanxuan/blog/2222" to "http://localhost/blog/index.php/user/blog/fanxuan/2222" ,but I failed , it prints 404 Error.

Quote:fanxuan is username
2222 is blog id;
Could someone give me some tips how to set the routes to meet my need?

Many many thanks!!
#2

[eluser]Michael Wales[/eluser]
The reason your route failed is because of the trailing slash within the $route key, try:
Code:
$route['user/(:any)/blog/(:num)'] = 'user/blog/$1/$2';


Also, why go through the URI library when you could just pass those values to the method itself?
Code:
function blog($user, $id) {




Theme © iAndrew 2016 - Forum software by © MyBB