Home > General > Examples about Writing URLs in Zend Framework

Examples about Writing URLs in Zend Framework

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.

<?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.

 
// 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.

<?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.

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://www.oplabo.com/article/30/trackback
Listed below are links to weblogs that reference
Examples about Writing URLs in Zend Framework from Open Programming Laboratory

Home > General > Examples about Writing URLs in Zend Framework

Japanese
Search
Feeds

Return to page top