How to access the Layout object in the Zend Framework plugin?

I am trying to use a layout for every action in the controller. For example, I have three actions in the index controller. These are indexAction, testAction and welcomeAction. I created three xml layout files. index.xml, test.xml and welcome.xml. Finally, I created a plugin.

class Moon_Layout_Append extends Zend_Controller_Plugin_Abstract{

 public function preDispatch($request){


  $layoutFile = APPLICATION_PATH."/Modules/".$request->module."/layout/".$request->action.".xml";

  $layout = new Zend_Config_Xml($layoutFile,'index');


 }

}

the problem is ... how do I access the layout object to set the content that I read from xml?

+3
source share
3 answers

The layout function can be easily accessed using the Action Manager Assistant. You should be able to get an auxiliary layout element using the following line.

$layout= Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');

Zend_Application , :

Zend_Layout::startMvc();
+4

, , xml layout.phtml

http://www.goodcomputingtips.com/site/2010/09/part-5-adding-menus-using-zend_navigation-a-not-so-quick-quickstart-to-zend-framework/

:

protected function _initNavigation() {
$this->bootstrap("layout");
$layout = $this->getResource('layout');     
$view = $layout->getView();

$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav');
$navigation = new Zend_Navigation($config);

$view->navigation($navigation); }

layout.phtml

<?php echo $this->navigation()->menu()->setMaxDepth(1); ?>

.

+1

Only worked for me

$layout = Zend_Layout::getMvcInstance(); 

and

 $layout= Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');

does not work.

+1
source

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


All Articles