-- Emanuele Deserti <[EMAIL PROTECTED]> wrote
(on Thursday, 28 February 2008, 03:28 PM +0100):
> > $this->getLocale and $this->setLocale are impossible to work because $this
> > is the view itself... from within the view you can only call view helpers.
> > And the error you get is saying that there is no helper named "getLocale"
> > which is correct... it would also throw an error on setLocale because the
> > helper is named translate().
> >
> > The correct way is described within the manual:
> > $this->translate()->getLocale()
>
>
> Yes yes I understand this, but my code is the exactly code that you can
> find in Zend Framework manual...
>
> Even this (in view): <?php echo $this->translate()->getLocale(); ?>
>
> Will output this error: "Fatal error: Call to a member function getLocale()
> on a non-object"
You need to attach a translation object to the helper first! You can do
this either through the registry (attach a Zend_Translate object in the
'Zend_Translate' key of the registry), or attach it to the helper with:
$this->translate()->setTranslator($translate);
// or, from your action controller:
$this->view->translate()->setTranslator($translate);
// or operating on the view object:
$view->translate()->setTranslator($translate);
> I think that translate() without any string passed as parameter will not
> return $this if there is a Zend_Translate instance registered in Registry
> as I can understand this code...
> PHP never enter in the second IF because Zend_Translate is registered
> before (in my Controller) and the "return $this" is never executed.
Based on the code you pasted, you're using an out-of-date version of the
helper. The current one reads as follows:
if (null === $messageid) {
return $this;
}
if (null === ($translate = $this->getTranslator())) {
return $messageid;
}
and only then attempts to translate the string. Please grab either the
current RC1 or current svn trunk.
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/