I have a login.phtml view that would like to put in a common path and get it accessed by any module through the application.
For sidebars rendered by $this->render('common/sidebar.phtnl')
it works since my layout is a single one for all modules.
But when it comes to the content $this->layout()->content
, if I add a helper to the result view like $this->login()
Zend keeps looking for it on the module scripts path.
How can it be possible to make my content view render another common view througth a helper even if my flow is a result of a module?
From view script you can:
This looks like a good job for a custom view helper. Writing your own is very easy and once you've tried it you won't be able to stop!
Your custom view helper should go in applications/views/helpers/NameOfHelper.php and should have a public method called nameOfHelper(). I'll use login as an example as that is your use case on this occassion.
First create applications/views/helpers/Login.php:-
Then in the view or layout simply do:-
and get the output:-
Couldn't be easier!
Alternatively if you want to use a view script you can do this in your login() method:-
Then when you do
echo $this->login()
in your view or layout you will see the output you want.Obviously, you can put whatever code you want into the login() method.