Calling a view from another view

I have a login.phtml view that would like to put a common path and access it with any module through the application.

For the $this->render('common/sidebar.phtnl') displayed by $this->render('common/sidebar.phtnl') , this works, since my layout is the same for all modules.

But when it comes to the content $this->layout()->content , if I add an assistant to the presentation of the result, for example, $this->login() Zend continues to search for it in the module script path.

How can I make my content view display a different general view, helping the assistant, even if my stream is the result of a module?

+4
source share
2 answers

This looks like a good job for a custom browsing assistant . Writing your own is very simple, and as soon as you try, you cannot stop!

Your own view helper should be in applications / views / helpers / NameOfHelper.php and should have a public method nameOfHelper (). I use the login as an example, as this is your use case in this case.

First create applications / views / helpers / Login.php: -

 class Zend_View_Helper_Login extends Zend_View_Helper_Abstract { public function login() { return "Logging in!"; } } 

Then in the view or layout just do: -

 echo $this->login(); 

and get the result: -

Logging in!

It couldn't be easier!

Alternatively, if you want to use a script view, you can do this in your login () method: -

 class Zend_View_Helper_Login extends Zend_View_Helper_Abstract { public function login() { $this->view->exampleVar = 'example value'; return $this->view->render('login.phtml') } } 

Then, when you do echo $this->login() in your view or layout, you will see the desired result.

Obviously, you can put any code in the login () method.

+1
source

From the script view, you can:

 <?php echo $this->render("menus/recetas.phtml"); ?> 
0
source

Source: https://habr.com/ru/post/1396137/


All Articles