0

I want to create a module with a form when clicking on menu tab, I have tried to exactly create it like what we have under System->MyAccount, but when I click on Example the menu is empty.I started with this example and changed it. here is my effort: enter image description here

config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_Adminhello>
            <version>1.0.0</version>
        </Custom_Adminhello>
    </modules>
        <admin>
        <routers>
            <adminhello>
                <use>admin</use>
                <args>
                    <module>Custom_Adminhello</module>
                    <frontName>admin</frontName>
                </args>
            </adminhello>
        </routers>
    </admin>

    <global>
        <helpers>
            <custom_adminhello>
                <class>Custom_Adminhello_Helper</class>
            </custom_adminhello>
        </helpers>
         <blocks>
            <custom_adminhello>
                <class>Custom_Adminhello_Block</class>
            </custom_adminhello>
        </blocks>
    </global>
</config>

adminhtml.xml:

<config>
    <menu>
        <custom translate="title" module="custom_adminhello">
            <title>Custom Module</title>
            <sort_order>1</sort_order>
            <children>
                <example>
                    <title>Example</title>
                    <sort_order>1</sort_order>
                    <action>adminhello/system_account</action>
                </example>
            </children>
        </custom>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>                
                    <custom translate="title" module="custom_adminhello">
                        <title>Example Menu Item</title>
                        <sort_order>1</sort_order>
                        <children>
                            <example>
                                <title>Example Menu Item</title>
                            </example>
                        </children>
                    </custom>
                </children>
            </admin>
        </resources>
    </acl>

</config> 

AccountController.php

class Custom_Adminhello_System_AccountController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->_title($this->__('System'))->_title($this->__('My Account'));

        $this->loadLayout();
        $this->_setActiveMenu('system/account');
        $this->_addContent($this->getLayout()->createBlock('adminhello/system_account_edit'));
        $this->renderLayout();
    }


}

Data.php:

class Custom_Adminhello_Helper_Data extends Mage_Core_Helper_Abstract
{
}    

Edit.php:

class Custom_Adminhello_Block_System_Account_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();

        $this->_controller = 'system_account';
        $this->_updateButton('save', 'label', Mage::helper('adminhello')->__('Save Account'));
        $this->_removeButton('delete');
        $this->_removeButton('back');
    }

    public function getHeaderText()
    {
        return Mage::helper('adminhello')->__('My Account');
    }
}

Form.php

class Custom_Adminhello_Block_System_Account_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $userId = Mage::getSingleton('admin/session')->getUser()->getId();
        $user = Mage::getModel('admin/user')
            ->load($userId);
        $user->unsetData('password');

        $form = new Varien_Data_Form();

        $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('adminhtml')->__('Account Information')));

        $fieldset->addField('username', 'text', array(
                'name'  => 'username',
                'label' => Mage::helper('adminhtml')->__('User Name'),
                'title' => Mage::helper('adminhtml')->__('User Name'),
                'required' => true,
            )
        );

        $fieldset->addField('firstname', 'text', array(
                'name'  => 'firstname',
                'label' => Mage::helper('adminhtml')->__('First Name'),
                'title' => Mage::helper('adminhtml')->__('First Name'),
                'required' => true,
            )
        );

        $fieldset->addField('lastname', 'text', array(
                'name'  => 'lastname',
                'label' => Mage::helper('adminhtml')->__('Last Name'),
                'title' => Mage::helper('adminhtml')->__('Last Name'),
                'required' => true,
            )
        );

        $fieldset->addField('user_id', 'hidden', array(
                'name'  => 'user_id',
            )
        );

        $fieldset->addField('email', 'text', array(
                'name'  => 'email',
                'label' => Mage::helper('adminhtml')->__('Email'),
                'title' => Mage::helper('adminhtml')->__('User Email'),
                'required' => true,
            )
        );

        $fieldset->addField('current_password', 'obscure', array(
                'name'  => 'current_password',
                'label' => Mage::helper('adminhtml')->__('Current Admin Password'),
                'title' => Mage::helper('adminhtml')->__('Current Admin Password'),
                'required' => true,
            )
        );

        $fieldset->addField('password', 'password', array(
                'name'  => 'new_password',
                'label' => Mage::helper('adminhtml')->__('New Password'),
                'title' => Mage::helper('adminhtml')->__('New Password'),
                'class' => 'input-text validate-admin-password',
            )
        );

        $fieldset->addField('confirmation', 'password', array(
                'name'  => 'password_confirmation',
                'label' => Mage::helper('adminhtml')->__('Password Confirmation'),
                'class' => 'input-text validate-cpassword',
            )
        );

        $form->setValues($user->getData());
        $form->setAction($this->getUrl('*/system_account/save'));
        $form->setMethod('post');
        $form->setUseContainer(true);
        $form->setId('edit_form');

        $this->setForm($form);

        return parent::_prepareForm();
    }
}
1

You can use https://www.magentocommerce.com/magento-connect/ultimate-module-creator.html extension its free and simple. Try and mark ans as correct.

  • have you placed xml file in app/etc/module – Anup Chaudhary Jan 29 '16 at 5:59
  • yes it is there – Nickool Jan 29 '16 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.