---------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

相关文章

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Python中的魔术方法__new__详解

《Python中的魔术方法__new__详解》:本文主要介绍Python中的魔术方法__new__的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、核心意义与机制1.1 构造过程原理1.2 与 __init__ 对比二、核心功能解析2.1 核心能力2.2

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

Mybatis 传参与排序模糊查询功能实现

《Mybatis传参与排序模糊查询功能实现》:本文主要介绍Mybatis传参与排序模糊查询功能实现,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、#{ }和${ }传参的区别二、排序三、like查询四、数据库连接池五、mysql 开发企业规范一、#{ }和${ }传参的

Java实现文件图片的预览和下载功能

《Java实现文件图片的预览和下载功能》这篇文章主要为大家详细介绍了如何使用Java实现文件图片的预览和下载功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... Java实现文件(图片)的预览和下载 @ApiOperation("访问文件") @GetMapping("

SpringKafka消息发布之KafkaTemplate与事务支持功能

《SpringKafka消息发布之KafkaTemplate与事务支持功能》通过本文介绍的基本用法、序列化选项、事务支持、错误处理和性能优化技术,开发者可以构建高效可靠的Kafka消息发布系统,事务支... 目录引言一、KafkaTemplate基础二、消息序列化三、事务支持机制四、错误处理与重试五、性能优

SpringIntegration消息路由之Router的条件路由与过滤功能

《SpringIntegration消息路由之Router的条件路由与过滤功能》本文详细介绍了Router的基础概念、条件路由实现、基于消息头的路由、动态路由与路由表、消息过滤与选择性路由以及错误处理... 目录引言一、Router基础概念二、条件路由实现三、基于消息头的路由四、动态路由与路由表五、消息过滤