views:

48

answers:

1

How to call model or controller functions in view.

Can we use functions operating database queries in helper ? How ? example ?

+1  A: 

To access the view in a view helper:

/**
 * The View in use
 * @var Zend_View_Interface
 */
public $view;

/**
 * Apply View
 * @param Zend_View_Interface $view
 */
public function setView (Zend_View_Interface $view) {
    # Set
    $this->view = $view;

    # Chain
    return $this;
}

To get the Controller from a View Helper is poor design and should be discouraged. View Helpers should not know anything about the Controller and be agnostic in that sense. However it is still possible via the Action View Helper: http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.action

As well as Controllers should not know anything about the View Helpers. If you would like something used by both View Helpers and Action (Controller) Helpers then create a Front Controller Plugin. You can then use Zend_Controller_Front::getInstance()->getPlugin('Bal_Controller_Plugin_Url'); to grab it.

balupton