views:

111

answers:

6

Greetings everyone

Using the request object, I can't get a sole value as in this URI:

http://mydomain.com/controller/action/value1

Using $request->getParams() is not returning the value1.

Output:

array([controller] => 'controller', [action] => 'action')

The key is missing.

The issue itself is quite simple and I could parse the URI myself, but actually I want ZF to do it (right?). I couldn't find a hint using google or on SO.

How am I able to get a key without a value?

A: 

Try modifying your routes by adding the needed field.

erenon
A: 

Well whats the route it looks like map to? If its the default route then this should be expected because it relies on the parsing rule key/value.

If it doesnt follow that simple rule then you need to create a new route to match the rule for that particular URI.

In general if you think you have a key that will not have a value you need to supply a default for that value in the route.

prodigitalson
A: 

http://mydomain.com/controller/action/param/value1/

array([controller] => 'controller', [action] => 'action', [param] => 'value1');

If you want this like iin your example you have to make your own route.

moof
+5  A: 

For default, Zend Framework expects the parameters in URL to be in the form of /key/value. Try this:

http://mydomain.com/controller/action/key1/value1

print_r($request->getParams());

The result is:

Array
(
    [controller] => controller
    [action] => action
    [key1] => value1
)

Edit: as others mentioned, If you want to stick with http://mydomain.com/controller/action/value1 you should take a look at Zend_Controller_Router.

Luiz Damim
A: 

By default, rails style URL parsing will be used. So for your purposes you would want:

http://mydomain.com/controller/action/key1/value1

You can configure the router though so that you would not have to use the key1 part. See the docs:

http://framework.zend.com/manual/en/zend.controller.router.html

smack0007
A: 

Define your route in the routes.ini file as follows (if value1 is a decimal value, if not change the regular expression to fit your needs):

routes.your_route.route = "controller/action/:value1"
routes.your_route.defaults.controller = "controller"
routes.your_route.defaults.action = "action"
routes.your_route.reqs.value1 = "\d+"

Then you can access the value in your action using getParam(s).

wimvds