Question

I have built a system that conforms to the mvc pattern in PHP. The controllers and actions are part of the urls in my application. So I have:

www.example.com/controller/action/

So now I am looking for a way to pass on variables. For forms I just use the post method, but sometimes I would just like to link to a different page and then pass on some variables.

I would like some suggestions on how to do this. I know the Zend Framework has the variables as key/value pairs after the action in the controller using the "/" character as a separator, like this:

www.example.com/controller/action/var1/value1/var2/value2

Is this the best way? This is actually the only way I know it's done. I am looking for an easy but yet good way to implement it.

Any suggestions are welcome.

1
5
4/13/2009 9:47:37 PM

Frameworks like CodeIgniter let you pass the variables into the controller without disclosing the variable name -

/controller/action/foo/bar/

would get processed as:

function action( $id, $value){
  echo $id; // outputs 'foo'
  echo $value; // outputs 'bar'
}

http://codeigniter.com/user_guide/general/controllers.html

I like this as it gives you control of how many parameters your controller will accept, and if it is important that certain variables are never used, you can do logic or redirect appropriately.

5
4/13/2009 9:36:47 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon