微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

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

原文地址:https://www.jb51.cc/ajax/164260.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐