现在的位置: 首页 > 综合 > 正文

———new——–magento–后台显示编辑框,用来编辑和插入功能!!!

2013年08月04日 ⁄ 综合 ⁄ 共 4393字 ⁄ 字号 评论关闭


1
访问后台路径/../index/bao
转向下面的方法

2
class AQ_Gao_IndexController extends Mage_Adminhtml_Controller_Action{
public function baoAction(){
   
        $this->loadLayout();
        $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
        $this->_addContent($this->getLayout()->createBlock('gao/manage_gao_edit'))
             ->_addLeft($this->getLayout()->createBlock('gao/manage_gao_edit_tabs'));
        $this->renderLayout();
}
通过addContent(),addLeft()方法,可以不用在layout.xml文件中写。

3
在magento中组件的使用:
magento把一些控件的使用默认封装起来,访问路径有默认路径。譬如edit,grid等
例子:Edit
/Edit.php
/Edit/Form.php
/Edit/Tabs.php
/Edit/Tab/Form.php
/Edit/Tab/Option.php

3.1
/Edit.php

<?php
class AQ_Gao_Block_Manage_Gao_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{
    public function __construct(){
        parent::__construct();
        //在URL中存放ID的参数名称。譬如www.fdfd.com/id/322,
        $this->_objectId = 'id';
        //模块名字,用来组建默认路径。
        $this->_blockGroup = 'gao';
        //Block和当前文件之间的路径名字。用来组件默认路径
        $this->_controller = 'manage_gao';
       
        $this->updateButton('save','label','Save Post');
        $this->updateButton('delete','label','Delete Post');

        $this->addButton('saveandcontinue',array(
            'label'  =>Mage::helper('adminhtml')->__('Save And Continue Edit'),
            'onclick'=>'saveAndContinueEdit()',
            'class'  =>'save',

        ),-100);
   
    }

    public function getHeaderText(){
        return 'AAdd Post';
   

    }
}
由该类的父类的
_prepareLayout()方法:
$this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));
得出其子block。/Edit/Form.php

3.2
/Edit/Form.php
<?php

class AQ_Gao_Block_Manage_Gao_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
    protected function _prepareForm(){
        $form = new Varien_Data_Form(array(
                        //这个id是做什么的还真不是很清楚,应该是做路径生成用的
                        'id' =>'edit_form',
                        //点击save按钮后访问的路径。
                        'action'=>$this->getUrl('*/*/save',array('id'=>$this->getRequest()->getParam('id'))),   
                        //提交方式。       
                        'method'=>'post',
   
                        ));
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();

    }

}

3.3
addLeft------->
/Edit/Tabs.php
<?php

class AQ_Gao_Block_Manage_Gao_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs{

    public function __construct(){
        parent::__construct();
        $this->setId('gao_tabs');
        $this->getDestElementId('edit_form');
        $this->setTitle('Post Information');

    }
    protected function _beforeToHtml(){
        //在左边显示的2个大分类。点击后对应不同的项
        $this->addTab('form_section',array(
        'label' =>'post Information',
        'title' =>'post Informationsss',
        'content'=>$this->getLayout()->createBlock('gao/manage_gao_edit_tab_form')->toHtml(),           
        ));

        $this->addTab('options_section',array(
        'label'=>'Advanced Options',
        'title'=>'Advanced Options',
        'content' =>$this->getLayout()->createBlock('gao/manage_gao_edit_tab_options')->toHtml(),

       
        ));
    return parent::_beforeToHtml();

    }   

}

3.4
/Edit/Tab/Form.php

<?php

class AQ_Gao_Block_Manage_Gao_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form{

    protected function _prepareForm(){
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('gao_form', array('legend'=>'Post information'));
       
        $fieldset->addField('title', 'text', array(
          'label'     => 'Title',
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'title',
        ));
    return parent::_prepareForm();
}

}

3.5
/Edit/Tab/Option.php
<?php

class AQ_Gao_Block_Manage_Gao_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget_Form{

    protected function _prepareForm(){
       
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('gao_form', array('legend'=>'Meta Data'));
       
        $fieldset->addField('meta_keywords', 'editor', array(
            'name' => 'meta_keywords',
            'label' => 'Keywords',
            'title' => 'Meta Keywords',
            'style' => 'width: 520px;',
        ));
    return parent::_prepareForm();
    }

}

OK,到这里就可以显示出来了!!

 

注意事项:

class AQ_Gao_Block_Manage_Gao_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs{

    public function __construct(){
  
        $this->getDestElementId('edit_form');///////////

class AQ_Gao_Block_Manage_Gao_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
    protected function _prepareForm(){
        $form = new Varien_Data_Form(array(
                        'id' =>'edit_form',///////////////////

和这个ID的值要一样,通过这种方式建立起来关联!!!

抱歉!评论已关闭.