Magento - 返回不带Layout的页面输出

你至少有三种方法可以返回不带Layout的页面输出

1. 在controller的action方法中直接echo 然后 return.
public function helloAction(){
   echo 'How are you';
   exit;
}


2. 在controller的代码方式创建并输出block内容
$this->loadLayout();
$this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/catalog_product_grid')->toHtml()
);


3. 一旦使用PHTML模板文件,有如下两种方法完成同样效果
1).使用core/text_list的Block命名为root
<your_frontname_controller_action>
	<block type="core/text_list" name="root">
		<block type="block1" name="block1" template="block1.phtml"/>
		<block type="block2" name="block2" template="block2.phtml"/>
	</block>
</your_frontname_controller_action>


2). 建立空的layout文件,如
a). page/empty.phtml内容如下:
<?php echo $this->getChildHtml('content') ?>

b). layout的文件声明可能如下
<your_frontname_controller_action translate="label">
  <reference name="root">
    <action method="setTemplate"><template>page/empty.phtml</template />
  </reference>
  <reference name="content">
    <block type="{your_block} name="{blockname}" template="{your_template_file.phtml}" />
  </reference>
</your_frontname_controller_action>


第2种方法使用是最频繁的

你可能感兴趣的:(PHP)