2

Is there a way of generating a full url in zend if the Module, controller and view names are known?

1 Answer 1

3

I'm assuming you mean module, controller, and action, since the view is determined by the action (usually).

In the view:

echo $this->url(array('module' => $module, 
                      'controller' => $controller, 
                      'action' => $action));

Any parameters not set, default to the current values, so in any given view:

echo $this->url(); //link for the current request

The function also accepts two additional arguments: url($urlOptions, $name, $reset). $name allows you to specify a route name, and $reset will clear the generated URL of any current parameters.

In the controller:

This actually isn't documented, but follows the structure of the redirector helper (in fact, I believe it is used by the redirector helper):

$url = $this->getHelper('url')->simple($action, $controller, $module, $params);

You can also use the url() method, which follows the View helper:

$url = $this->getHelper('url')->url(array('module' => $module, 
                                          'controller' => $controller, 
                                          'action' => $action));
Sign up to request clarification or add additional context in comments.

3 Comments

@Tobi - if it answers your question, hit the 'check-mark' to show that.
Worth adding that each of the vars module, controller and action are optional. If you omit them it'll default to the values in the page you're rendering it in.
@JamesC Indeed, I mentioned the reset flag, which clears that, but I'll update the answer so the default values are clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.