閱讀304 返回首頁    go 阿裏雲 go 技術社區[雲棲]


magento 開發--另一種方式用xml來布局

是否厭倦了用xml文件來做Magento的頁麵布局,是的話來試試下麵這種方式,把布局代碼寫到controller 裏麵

 

public function mycoolAction() { /* ... Some code ...*/ $update = $this->getLayout()->getUpdate(); /* ... Some code ...*/ $this->addActionLayoutHandles(); /* ... Some code ...*/ $this->loadLayoutUpdates(); /* ... Some code ...*/ /* My stuff, add pure XML like you do from XML layout files <img src="https://inchoo.net/wp-includes/images/smilies/icon_smile.gif" mce_src="https://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" > */ $update->addUpdate(' <reference name="head"> <action method="addJs"><mce:script type="text/javascript"><!-- varien/product.js // --></mce:script></action> <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params /><!--<if/><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if /><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if /><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>skin_js</type><name>js/bundle.js</name></action> </reference> '); /* ... Some code ...*/ $this->generateLayoutXml()->generateLayoutBlocks(); /* ... Some code ...*/ $this->renderLayout(); }

 

這樣你也許就可以少新建一些xml文件

當然,這裏還是推薦把布局寫在xml文件裏,上麵這種方式隻是告訴你Magento還有另一種方式來實現相同的功能

最後更新:2017-04-02 05:21:05

  上一篇:go java.security.MessageDigest的使用(2),生成安全令牌!
  下一篇:go AVL樹的刪除探討