Welcome Guest, Not a member yet? Register   Sign In
Pass a Variable to the default_controller Via /$variable, How?
#1

[eluser]jmrhoades[/eluser]
In routes.php I have:
Code:
$route['default_controller'] = "schedule";

my /controllers/schedule.php file looks like this:
Code:
<?php
class Schedule extends Controller {
    
    function Schedule()
    {
        parent::Controller();
    }
        
    function index($scheduleUrl = null)
    {
        if ($scheduleUrl)
        {
            echo $scheduleUrl;
        }
        else
        {
            echo "Default message";    
        }    
    }
}
?>


I can't figure out a way to pass an argument to the default index() function of my Schedule controller. I've tried URI routing like this to no avail:

Code:
$route['/(.+)'] = 'schedule/index/$1'
Code:
$route['/(.+)'] = '/index/$1'
Code:
$route[':any'] = '/index/$1'

I'm trying to use url's that look like
Code:
www.somesite.com/this-is-a-var
and have "this-is-a-var" passed to my default controller's index() function. www.somesite.com/schedule/index/this-is-a-var works, but that way too verbose. I thought that this thread had the answer, but I couldn't get any of those techniques to work. Ideas?
#2

[eluser]jmrhoades[/eluser]
Never mind, I'm an idiot.
This did the trick in routes.php:
Code:
$route['(:any)'] = "schedule/index/$1";




Theme © iAndrew 2016 - Forum software by © MyBB