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

2024-03-25 14:38

本文主要是介绍---------new--------magento--后台显示编辑框,用来编辑和插入功能!!!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


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的值要一样,通过这种方式建立起来关联!!!

这篇关于---------new--------magento--后台显示编辑框,用来编辑和插入功能!!!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/845311

相关文章

深度解析Spring Security 中的 SecurityFilterChain核心功能

《深度解析SpringSecurity中的SecurityFilterChain核心功能》SecurityFilterChain通过组件化配置、类型安全路径匹配、多链协同三大特性,重构了Spri... 目录Spring Security 中的SecurityFilterChain深度解析一、Security

Java实现预览与打印功能详解

《Java实现预览与打印功能详解》在Java中,打印功能主要依赖java.awt.print包,该包提供了与打印相关的一些关键类,比如PrinterJob和PageFormat,它们构成... 目录Java 打印系统概述打印预览与设置使用 PageFormat 和 PrinterJob 类设置页面格式与纸张

MySQL 8 中的一个强大功能 JSON_TABLE示例详解

《MySQL8中的一个强大功能JSON_TABLE示例详解》JSON_TABLE是MySQL8中引入的一个强大功能,它允许用户将JSON数据转换为关系表格式,从而可以更方便地在SQL查询中处理J... 目录基本语法示例示例查询解释应用场景不适用场景1. ‌jsON 数据结构过于复杂或动态变化‌2. ‌性能要

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构

Go语言中make和new的区别及说明

《Go语言中make和new的区别及说明》:本文主要介绍Go语言中make和new的区别及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1 概述2 new 函数2.1 功能2.2 语法2.3 初始化案例3 make 函数3.1 功能3.2 语法3.3 初始化

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

Golang如何用gorm实现分页的功能

《Golang如何用gorm实现分页的功能》:本文主要介绍Golang如何用gorm实现分页的功能方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景go库下载初始化数据【1】建表【2】插入数据【3】查看数据4、代码示例【1】gorm结构体定义【2】分页结构体

Java Web实现类似Excel表格锁定功能实战教程

《JavaWeb实现类似Excel表格锁定功能实战教程》本文将详细介绍通过创建特定div元素并利用CSS布局和JavaScript事件监听来实现类似Excel的锁定行和列效果的方法,感兴趣的朋友跟随... 目录1. 模拟Excel表格锁定功能2. 创建3个div元素实现表格锁定2.1 div元素布局设计2.

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各