Welcome Guest, Not a member yet? Register   Sign In
URI Segments type
#1

[eluser]Valdemar[/eluser]
Hi there!

I don't know if that's already asked. I tried to search in the forums but couldn't find anything similar to my question.

So here it is...

I have the following URL:

http://www.example.com/shoes/color/black/

This will result in 3 URI segments: shoes, color and black. It's obvious that the first segment is always either the controller itself or the directory where the controller is residing (that can be easily checked).

My question is, how can I distinguish if color is a method or simply a passed variable. Consider the following short example:

Code:
<?php
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }
    
    function index($property,$value){
        echo $property; // Produces: color
        echo $value;    // Produces: black    
    }
}
?>

and

Code:
<?php
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }
    
    function index(){
        /* Some index stuff here.. */
    }
    
    function color($value){
        echo $value; // Produces black
    }
}
?>

Both examples should produce one and the same thing after all, but if I don't know the exact implementation of the shoes controller, how can I distinguish if color is a method or a passed variable?

I hope I was able to explain the situation clearly.

Thank you in advance!
#2

[eluser]Michael Wales[/eluser]
The second segment is always the method unless you implement routing to change it.

To call your first function (and pass parameters to it) you would use a URL like:
domain.com/test/index/color/black
#3

[eluser]Valdemar[/eluser]
Thanks!

I guess it was easier than I thought it Smile And hey, congrats on your 888th post Tongue




Theme © iAndrew 2016 - Forum software by © MyBB