CodeIgniter Forums
routes issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: routes issue (/showthread.php?tid=8098)

Pages: 1 2


routes issue - El Forum - 05-05-2008

[eluser]AtlantixMedia[/eluser]
Hello,

I'm having some issue getting routes to work.

Code:
$route['info/strategy/(.*)'] = "info/strategy/pick/$1";


class Strategy extends Controller {

    //=======================
    function Strategy()
    //=======================
   {
        parent::Controller();
    }

    //=======================        
    function index()
    //=======================    
    {
        $this->Pick();
    }

    //=======================        
    function Pick($strategy = 'project-discovery')
    //=======================    
    {
            echo $strategy;

    }


}

the following url http://www.domain.com/info/strategy/sketches ( and any other url where only the last segment changes ) do not throw any error. however, the echo statement always echoes the string 'project-discovery' even though it should echo the string 'sketches'. am I missing something?


routes issue - El Forum - 05-05-2008

[eluser]christian.schorn[/eluser]
I can't vouch for it, but maybe it will work if you put single quotes around the target string of the route, like this:
Code:
$route['info/strategy/(.*)'] = 'info/strategy/pick/$1';



routes issue - El Forum - 05-05-2008

[eluser]AtlantixMedia[/eluser]
no. it doesn't make any difference. also, the samples in the CI user guide use double quotes


routes issue - El Forum - 05-06-2008

[eluser]AtlantixMedia[/eluser]
also, if I comment the route out and use this url http://www.domain.com/info/strategy/pick/sketches to access the controller, the echo statement successfully prints 'sketches'


routes issue - El Forum - 05-06-2008

[eluser]xwero[/eluser]
I guess http://www.domain.com/info is the basepath? As the name of the controller is Strategy. The routes start behind the index.php file if you hide it or not.


routes issue - El Forum - 05-06-2008

[eluser]AtlantixMedia[/eluser]
info is a folder
strategy is a controller
pick is a function
sketches is a parameter

I basically want to shorten the url so that users only see info/strategy/whatever


routes issue - El Forum - 05-06-2008

[eluser]xwero[/eluser]
you have to capitalize pick in the route because the function is
Code:
$route['info/strategy/(.*)'] = "info/strategy/Pick/$1";
That is a bang your head against the desk error Smile


routes issue - El Forum - 05-06-2008

[eluser]AtlantixMedia[/eluser]
not really. I don't believe you have to capitalize functions to access them. anyway, I tried that but it still doesn't work!

$route['info/strategy/(.*)'] = "info/strategy/Pick/$1";


routes issue - El Forum - 05-06-2008

[eluser]xwero[/eluser]
No you don't have to capitalize functions but because you did the function is only callable capitalized. I did have some problems with it anyway.

What is the output if you add to the pick function
Code:
echo $this->uri->segment(4)

I think your problem has to do with the fact in your index function you call the pick function. I think you don't need routing if you do this
Code:
function index()
    {
        $this->Pick($this->uri->segment(3));
    }



routes issue - El Forum - 05-06-2008

[eluser]AtlantixMedia[/eluser]
[quote author="xwero" date="1210079419"]No you don't have to capitalize functions but because you did the function is only callable capitalized. I did have some problems with it anyway.

What is the output if you add to the pick function
Code:
echo $this->uri->segment(4)

I think your problem has to do with the fact in your index function you call the pick function. I think you don't need routing if you do this
Code:
function index()
    {
        $this->Pick($this->uri->segment(3));
    }
[/quote]

hold on one second: I always capitalize functions in controllers but ALWAYS use lowercase in url when accessing them and it always worked.

echo $this->uri->segment(4) will print an empty string. on the other hand, 3 will print sketches, 2 strategy, and 1 info.

I also commented whatever is in the index function. still, it's not working. as I said, it does not throw any error. It just does not seem to pass any parameter, so the default one is used.