Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend: How to use a custom function from a view helper in the controller?

Ive got a view helper in library/my/view/helper/gravatar and so in any view I can call $this->gravatar($email).

But how can I access this function in the models (or controllers)?

Sorry if its already been asked but Im new and the documentation is bloody awful in parts.

Thanks everyone

like image 941
bluedaniel Avatar asked Feb 28 '10 22:02

bluedaniel


2 Answers

In your controller, you can access ViewHelpers through

$this->view->gravatar($email)

Your model should not call methods from the View, as it would tie the model to the presentation layer. The View may know about the model, but the model should not know about the View.

For Gravatars, there is also a Service and View Helper in the making:

  • Zend_Service_Gravatar proposal
  • Zend_Service_Gravatar sourecode (in incubator)
  • Zend_ViewHelper_Gravatar proposal
like image 171
Gordon Avatar answered Oct 25 '22 06:10

Gordon


A better way to be sure the "thing" from the view is actually a view helper is to use the method getHelper("helperName");.

  $this->view->getHelper('gravatar');
like image 26
SandRock Avatar answered Oct 25 '22 07:10

SandRock