Welcome Guest, Not a member yet? Register   Sign In
Use function instead of a controller
#6

[eluser]CroNiX[/eluser]
One thing with routes...you need to have the order go from the uri with the most segments, to least.
Code:
$route['main/(:any)'] = "main/redirect"; //two segments, main + (:any)
$route['main'] = "main/redirect"; //one segment, main
In routes, you can also pass in any captured segments to the controller/method.
Code:
$route['main/(:any)'] = "main/redirect/$1"; //$1 will be (:any)
Then in main{}...
Code:
function redirect($url = null) //$url is (:any) from the route
{
  if ( ! is_null($url))
  {
    redirect($url);
  }
}
You also shouldn't have to have http:// AND base_url(). base_url() contains the http://, or at least it should in the config. Also, when using redirect(), CI adds the base_url() automatically so all you need to do is pass it the segments
Code:
redirect($this->uri->segment(2));  //redirects to base_url() + segments


Messages In This Thread
Use function instead of a controller - by El Forum - 01-25-2014, 03:14 PM
Use function instead of a controller - by El Forum - 01-25-2014, 09:15 PM
Use function instead of a controller - by El Forum - 01-26-2014, 05:05 AM
Use function instead of a controller - by El Forum - 01-26-2014, 05:15 AM
Use function instead of a controller - by El Forum - 01-26-2014, 08:40 AM
Use function instead of a controller - by El Forum - 01-26-2014, 01:07 PM
Use function instead of a controller - by El Forum - 02-06-2014, 11:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB