加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 00:18:52 所属栏目:百科 来源:网络整理
导读:Magento 通过xxAction改变模板 $ this -loadLayout(); $ this -getLayout()-getBlock( 'block_name' )-setTemplate( '/aa/bb/xxx.phtml' ); 这是通过ACTION 加载外部的 PHTML $ this -renderLayout(); public function profileAction() { // echo $this-getL

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>

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读