簡體   English   中英

在magento管理面板中創建表單

[英]Create a form in magento admin panel

我正在嘗試在magento的管理面板(自定義模塊)中創建表單。 目前,我的magento自定義模塊可以正常工作。 我在管理面板中創建了菜單,我重寫了一些控制器,但無法在管理面板中創建表單(單擊菜單項時)。 在config.xml中,我有下一部分代碼:

<admin>
            <routers>
                <test>
                    <use>admin</use>
                    <args>
                        <module>Mynamespace_Skipcart</module>
                        <frontName>Skipcart</frontName>
                    </args>
                </test>
            </routers>
        </admin>
        <adminhtml>
            <menu>
                <tutorial_menu translate="title" module="skipcart">
                    <title>Skip Cart</title>
                    <sort_order>9999</sort_order>
                    <children>
                        <first_page module="skipcart">
                            <title>Our First Page</title>
                            <action>Skipcart/Adminhtml_index/index</action>
                        </first_page>
                    </children>
                </tutorial_menu>
            </menu>
            <layout>
                <updates>
                    <skipcart>
                        <file>Skipcart.xml</file>
                    </skipcart>
                </updates>
            </layout>
        </adminhtml>

我在app / design / frontend / default / default / layout / skipcart.xml中有一個文件。 在此文件中,我創建了錯誤的文件。 使用這種方法,我檢查magento是否讀取了此文件。 如果magento讀取了skipcart.xml,則會返回警告:simplexml_load_string(),但magento不會返回錯誤。 我還有一個問題。 如果我將此代碼從adminhtml.xml中的config.xml移動到菜單,則管理面板中的菜單將消失。 我在magento 1.7上嘗試了我的模塊。 有誰能夠幫助我?

我在app / code / local / Mynamespace / Skipcart / controllers / Adminhtml / IndexController.php中有一個控制器

<?php

class Mynamespace_Skipcart_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action {
     public function indexAction()
    {
        $this->loadLayout();

        //create a text block with the name of "example-block"
        $block = $this->getLayout()
        ->createBlock('core/text', 'example-block')
        ->setText('<h1>This is a text block</h1>');

        $this->_addContent($block);
  //add menu active
        $this->_setActiveMenu('tutorial_menu/first_page');
       // $model = Mage::getModel('skipcart/skipcart'); Mage::log('da');
       // $this->_setActiveMenu('system/another_menu_from_us');
     // echo $block1 = $this->getLayout()->createBlock('skipcart/add');
      // $this->_addContent($block1);
        $this->renderLayout();


    }
    public function postAction()
    {
        $post = $this->getRequest()->getPost();
        try {
            if (empty($post)) {
                Mage::throwException($this->__('Invalid form data.'));
            }

            /* here's your form processing */

            $message = $this->__('Your form has been submitted successfully.');
            Mage::getSingleton('adminhtml/session')->addSuccess($message);
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
        $this->_redirect('*/*');
    }

}
?>

和skipcart.xml:

<?xml version="1.0"?>
<layout>
    <skipcart_adminhtml_index_index>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>

         <update handle="skipcart_index_index"/>
        <reference name="content">
            <block type="adminhtml/template" name="skipcart" template="skipcart/add.phtml"/>
        </reference>
    </skipcart_adminhtml_index_index>
<!-- I miss the <layout> because I want to check if magento read this file.-->

只需像下面那樣更改函數體,而不是core/text調用core/templatesetTemplate('filename.phtml'); 在此文件中,您需要添加表單html就是這樣。

public function indexAction()
{
    $this->loadLayout();

    //create a text block with the name of "example-block"
    $block = $this->getLayout()
    ->createBlock('core/template', 'example-block')
    ->setTemplate('folder/fileName.phtml');

    $this->_addContent($block);

    $this->_setActiveMenu('tutorial_menu/first_page');      

    $this->renderLayout();


} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM