intro
I’ve learned about writing url using helpers. The following content is about it. In this article, the base url is http://localhost/mybase/.
1.Examles about Writing URLs in Controller
The following content shows examples about getting URLs in controller.
The following content shows examples about doing redirect in controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php $options = array( 'action' => 'myaction', 'controller' => 'mycontroller', 'module' => 'mymodule' ); // '/mybase' $this->getRequest()->getBaseUrl(); // '/mycontroller/myaction' $this->_helper->url('myaction', 'mycontroller'); // '/mycontroller/myaction' $this->_helper->url('myaction', 'mycontroller', 'default'); // '/mymodule/mycontroller/myaction' $this->_helper->url('myaction', 'mycontroller', 'mymodule'); // '/mybase/mymodule/mycontroller/myaction' $this->_helper->url->url($options); |
The following content shows examples about doing redirect in controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// redirect to /mybase/mycontroller/myaction $this->_redirect('/mycontroller/myaction'); // redirect to http://somehost/ $this->_redirect('http://somehost/'); // redirect to /mybase/mycontroller/myaction $this->_helper->redirector('myaction', 'mycontroller'); // redirect to /mybase/mycontroller/myaction $this->_helper->redirector->gotoUrl('/mycontroller/myaction'); // redirect to /my.html $this->_helper->redirector ->setPrependBase(false) ->gotoUrl('/my.html'); |
2.Examles about Writing URLs in View
The following content shows an example about getting URLs in view.
1 2 3 4 5 6 7 8 |
<?php $options = array( 'action' => 'myaction', 'controller' => 'mycontroller', 'module' => 'mymodule'); ?> <!-- /mybase/mymodule/mycontroller/myaction --> <?= $this->url($options) ?> |
Reference
Related information about getting URLs of static file in view is on the following site.