0
votes

I am trying to create form in admin panel(custom module) in magento. For now my magento custom module work properly. I created menu in admin panel, I rewrite some controllers,but I cannot create a form in admin panel(when I click on the menu item). In config.xml I have next part of code:

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

I have a file in app/design/frontend/default/default/layout/skipcart.xml. In this file I created wrong. With this method I check if magento read this file. If magento read the skipcart.xml will return Warning: simplexml_load_string(), but magento doesn`t return a error. And I have one more problem. If I move this code for the menu from config.xml in adminhtml.xml the menu from the admin panel disappear. I trying my module on magento 1.7. Can anybody help me?

I have a controller in 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('*/*');
    }

}
?>

and 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.-->
1
<file>Skipcart.xml</file> - is with capital S ... below you are saying I have the file [...]skipcart.xml. (no capital S) ... - FlorinelChis
Sorry I just tried with capital, after that with small letter. Now and the file and in config.xml are with small letter. This is no the wrong :| - Anton_Sh
Can you post the contents for Skipcart.xml ... also, what form are you trying to display? (are the controller action and related blocks created?) - FlorinelChis
Looks to me that you are mixing a bit frontend and backend... what you are trying to achieve is a frontend page (setTemplate to page/2columns-left.phtml) using backend logic (your controller extends Mage_Adminhtml_Controller_Action) - FlorinelChis
OK, I deleted the (setTemplate to page/2columns-left.phtml), but no effect. I just tried to create admin form. This is not main problem. The main problem is that magento doesn`t read skipcart.xml (Think) - Anton_Sh

1 Answers

1
votes

Just Change your function body like that below instead of core/text call core/template and setTemplate('filename.phtml'); In this file you need to add your form html that's it.

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();


}