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

相关文章

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

MybatisPlus service接口功能介绍

《MybatisPlusservice接口功能介绍》:本文主要介绍MybatisPlusservice接口功能介绍,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友... 目录Service接口基本用法进阶用法总结:Lambda方法Service接口基本用法MyBATisP

Java反射实现多属性去重与分组功能

《Java反射实现多属性去重与分组功能》在Java开发中,​​List是一种非常常用的数据结构,通常我们会遇到这样的问题:如何处理​​List​​​中的相同字段?无论是去重还是分组,合理的操作可以提高... 目录一、开发环境与基础组件准备1.环境配置:2. 代码结构说明:二、基础反射工具:BeanUtils

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

Python中bisect_left 函数实现高效插入与有序列表管理

《Python中bisect_left函数实现高效插入与有序列表管理》Python的bisect_left函数通过二分查找高效定位有序列表插入位置,与bisect_right的区别在于处理重复元素时... 目录一、bisect_left 基本介绍1.1 函数定义1.2 核心功能二、bisect_left 与

解决mysql插入数据锁等待超时报错:Lock wait timeout exceeded;try restarting transaction

《解决mysql插入数据锁等待超时报错:Lockwaittimeoutexceeded;tryrestartingtransaction》:本文主要介绍解决mysql插入数据锁等待超时报... 目录报错信息解决办法1、数据库中执行如下sql2、再到 INNODB_TRX 事务表中查看总结报错信息Lock

Druid连接池实现自定义数据库密码加解密功能

《Druid连接池实现自定义数据库密码加解密功能》在现代应用开发中,数据安全是至关重要的,本文将介绍如何在​​Druid​​连接池中实现自定义的数据库密码加解密功能,有需要的小伙伴可以参考一下... 目录1. 环境准备2. 密码加密算法的选择3. 自定义 ​​DruidDataSource​​ 的密码解密3

SpringCloud使用Nacos 配置中心实现配置自动刷新功能使用

《SpringCloud使用Nacos配置中心实现配置自动刷新功能使用》SpringCloud项目中使用Nacos作为配置中心可以方便开发及运维人员随时查看配置信息,及配置共享,并且Nacos支持配... 目录前言一、Nacos中集中配置方式?二、使用步骤1.使用$Value 注解2.使用@Configur

idea中project的显示问题及解决

《idea中project的显示问题及解决》:本文主要介绍idea中project的显示问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录idea中project的显示问题清除配置重China编程新生成配置总结idea中project的显示问题新建空的pr

使用nohup和--remove-source-files在后台运行rsync并记录日志方式

《使用nohup和--remove-source-files在后台运行rsync并记录日志方式》:本文主要介绍使用nohup和--remove-source-files在后台运行rsync并记录日... 目录一、什么是 --remove-source-files?二、示例命令三、命令详解1. nohup2.