Zend Framework URL helper

There are two URL helpers in the Zend Framework that help generate URLs from action and controller names:

  1. Action helper: This has the signature url($action, $controller = null, $module = null, array $params = null)
  2. View Helper: Signature url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)

While using the Action helper, use the following code:

$url = $this->_helper->url(‘auth’,’login’);

Note that the controller and action are strings.

and, when using the View Helper function,

$url = $this->view->url(array(‘controller’=>’auth’,’action’=>’login’));

It is easy to mix up the syntax (And, if you do mix-up, you will get an additional “/Array” at the end of your url .. voice of experience :-))


3 thoughts on “Zend Framework URL helper

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s