Call assistants from Zend_Form
First of all, Zend_Viewit is not introduced in Zend_Form. Therefore, when you call $this->viewor $this->_view, it will not work, because nothing is returned. Why does it work getHelper()? Because it gets the view through a helper broker (and if you use viewRenderer). Take a look at the code below:
// Zend/Form.php
public function getView()
{
if (null === $this->_view) {
require_once 'Zend/Controller/Action/HelperBroker.php';
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$this->setView($viewRenderer->view);
}
return $this->_view;
}
This is the reason why it $this->_view->translate()works if you call getView()earlier, because it is stored as a protected property.
Accordingly, this code should work fine and works for me:
class My_Form extends Zend_Form
{
public function init()
{
echo $this->getView()->translate('name'); //fires 'translate' view helper and translating value
//below will also work, because you have view now in _view: getView() fetched it.
echo $this->_view->translate("another thing");
}
}
BTW. , . , - Zend_Form, :
Zend_Form::setDefaultTranslator($translator);
.