Magento 使用Ajax异步处理教程//setTemplate('/aa/bb/xxx.phtml')

Magento 通过xxAction改变模板

  1. $this->loadLayout();
  2. $this->getLayout()->getBlock('block_name')->setTemplate('/aa/bb/xxx.phtml'); 这是通过ACTION 加载外部的 PHTML
  3. $this->renderLayout();


public function profileAction() {
// echo $this->getLayout()->createBlock('core/template')->setTemplate('customer/form/profile.phtml')->setName('Bill Gates')->toHtml() ; 这是通过ACTION 加载外部 不建//议使用。。。。。。。

$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();

}


public function showAction()

{
$this->_title($this->__('老会员管理'))->_title($this->__('老会员管理'));

if ($this->getRequest()->getQuery('ajax')) {
$this->_forward('grid');
return;
}
$this->loadLayout();

$this->_setActiveMenu('customer/manage');

$this->renderLayout();
}


上面 showAction() 都是加载 SALES.XML 来进行配制的。。。

<adminhtml_customer_show>
<reference name="content">
<block type="adminhtml/customer_pool" name="sales.adminhtml.pool.grid" >

<!-- <block type="adminhtml/customer_pool_grid" name="sales.adminhtml.pool.grid" > -->

</block>
</reference>
</adminhtml_customer_show>



public function timeAction()
{//die('fdfdfdf');
$this->_title($this->__('CMS'))->_title($this->__('标题内容 '));

$this->_initaction();
$this->_addContent(
$this->getLayout()->createBlock('cms/adminhtml_timeorder') //这个是加载内部 在CMS --》 block 下面的 模块。。。。
);
$this->renderLayout();
}



Magento AJAX应用程序大概思路基本如下:

调用Magento AJAX主要去掉多余不想要的block结点数据,比如header,footer,left,right

1.通过controller修改配置文件的handle输出结果

    protected function loadPage() 
{
    $layout = $this->getLayout();
    $update = $layout->getUpdate();
    $update->load('your_custom_handle');
    $layout->generateXml();
    $layout->generateBlocks();
    $output = $layout->getoutput();

    $result = array( 'outputHtml' => $output, 'otherVar' => 'foo', );
    $this->getResponse()->setBody(Zend_Json::encode($result));        
}     

2.LAYOUT配置文件

<your_custom_handle>
    
    <remove name="head"/><!--去掉头部结点-->
    <remove name="right"/><!--去掉右边结点-->
    <remove name="left"/><!--去掉左边结点-->
 <block type="module/block" name="root" output="toHtml" template="module/template.phtml"/>
</your_custom_handle>

这样就可以输出内容返回给前端处理

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...