Zend Framework Source Code Snippets

Param view helper

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
<?php
 
/**
 * Retrieves requet param
 * * @category   Ds
 * @package    View
 * @subpackage Helper
 * @author     Michal "Techi" Vrchota <michal.vrchota@gmail.com>
 * @license    http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License v 3.0 */
 
require_once 'Zend/View/Helper/Abstract.php';
 
class Ds_View_Helper_Param extends Zend_View_Helper_Abstract  {
        /**
         * Retrieve param
         *
         * @param string $name key         * @return string
         */
        
    public function param($name)
    {          return Zend_Controller_Front::getInstance()->getRequest()->getParam($name);
    }  
}

Comments

Court Ewing Court Ewing
2 years ago

So simple, yet so extremely convenient. If you uncoupled it from the Zend_Controller_Front and allowed it to fall back on standard superglobals, it would be more helpful to a greater number of people.

Neantis Neantis
2 years ago

Well, I don't think params have to be used directly into views. What usecase requires it?

Court Ewing Court Ewing
2 years ago

For those of us that try to limit our use of controllers as much as possible, accessing "params" directly in a view script is a very common occurrence.

Techi Techi
2 years ago

Well I agree that is best to avoid working with params directly in template however sometimes it can be usefull

i.e. highlight link which represents current controller/action - is better to perform the task in template rather then in controller

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

<body class="<?= $this->param('controller') ?>">

Snippet details

Created:
Techi Techi
2 years ago
Edited:
Techi Techi
2 years ago
Revision Id:
17
Edit Message:
Initial Release
Tags:
view helper
Comments:
4
Views:
817
Points:
0 (0 votes)

History

r17

Initial Release

Techi Techi
2 years ago