using Zend's default routing a URL looks like:
www.domain.com/controller/action/key1/value1/key2/value2/key3/value3
Each Key and Value are stored as a pair in the array returned by getParams();
In this example:
array("key1" => "value1", "key2" => "value2", "key3" => "value3")
I want the parameter URLs to look like:
www.domain.com/controller/action/value1/value2/value3
The parameters should be mapped in an array like this. The key should depend just on the value's position in the URL.
array(0 => "value1", 1 => "value2", 2 => "value3")
How can I do this?
You are going to need to read up a bit on ZF Routes. But essentially what you need to do is add something like this to your Bootstrap.php:
The NULL's provide default values.
Then in your controller you will do something like this:
or use the getParams method you previously mentioned.
You can also use PHP's array_values() function to create a numerically indexed array like so:
It is a very good idea to get into the habit of using routes as they provide abstraction between what the URI is and what controllers/actions get invoked. Essentially, what you can achieve with routes is object-oriented code that still makes perfect sense to a programmer, while at the same time a URI that makes perfect sense to a user.
I had the same intention because i want my URL to look something like this:
I remember I can also Load everything from an .ini file, so i use this on my Bootstrap
Then I had this in my routes.ini
When you run
$this->_request->getParams()
in your controller, this will produce something like:It actually works pretty well :)