Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Writing a custom module! 
 
Clark Studios
Jr. Member
 
Total Posts:  4
Joined:  2009-05-20
 

Hi all,

I am writing a custom module just to try and learn how everything fits together. My main aim at the moment is to add a custom menu to the back end and have a page that just says hello world for now.

I have got the menu set up in the back end but am having real trouble with getting the link to work it keeps returning a 404. Here is a quick glance at part of the xml.

<admin>
        <
routers>
            <
homepageproduct>
                <use>
admin</use>
                <
args>
                    <
module>Bpgraphics_HomePageProduct</module>
                    <
frontname>homepageproduct</frontname>
                </
args>
            </
homepageproduct>
        </
routers>
    </
admin>

    <
adminhtml>
        <
menu>
            <
menu1 translate="title" module="homepageproduct">
                <
title>TESTING</title>
                <
sort_order>60</sort_order>
                <
children>
                    <
menuitem1 module="homepageproduct">
                        <
title>Administration</title>
                        
[b]<action>homepageproduct/adminhtml_testing</action>[/b]
                    
</menuitem1>
                </
children>
            </
menu1>
        </
menu>
     <
layout>
            <
updates>
                <
bpgraphics>
                    <
file>bpgraphics.xml</file>
                </
bpgraphics>
            </
updates>
        </
layout>
    </
adminhtml>

The line <action>homepageproduct/adminhtml_testing</action> controls where the link goes to. My folder structure is as follows.

BpGraphics
- HomePageProduct
-- controllers
--- Adminhtml
---- TestingController.php

Am I doing something fundamentally wrong here - I cant seem to find any documentation that makes any real sense and online examples although good do not really explain much.

===== ADDITIONAL

I have also got two files for the adminhtml layout and template these reside in

app/design/adminhtml/default/bpgraphics/template/testing.phtml
app/design/adminhtml/default/bpgraphics/layout/bpgraphics.xml

Would be greatful for any help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Damian Culotta
Enthusiast
 
Total Posts:  878
Joined:  2008-12-10
Argentina
 

Maybe this wiki article can help you

http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table

 
Magento Community Magento Community
Magento Community
Magento Community
 
Accilies
Jr. Member
 
Total Posts:  1
Joined:  2009-06-29
 
Clark Studios - 01 July 2009 12:17 AM

Hi all,

I am writing a custom module just to try and learn how everything fits together. My main aim at the moment is to add a custom menu to the back end and have a page that just says hello world for now.

I have got the menu set up in the back end but am having real trouble with getting the link to work it keeps returning a 404. Here is a quick glance at part of the xml.

<admin>
        <
routers>
            <
homepageproduct>
                <use>
admin</use>
                <
args>
                    <
module>Bpgraphics_HomePageProduct</module>
                    <
frontname>homepageproduct</frontname>
                </
args>
            </
homepageproduct>
        </
routers>
    </
admin>

    <
adminhtml>
        <
menu>
            <
menu1 translate="title" module="homepageproduct">
                <
title>TESTING</title>
                <
sort_order>60</sort_order>
                <
children>
                    <
menuitem1 module="homepageproduct">
                        <
title>Administration</title>
                        
[b]<action>homepageproduct/adminhtml_testing</action>[/b]
                    
</menuitem1>
                </
children>
            </
menu1>
        </
menu>
     <
layout>
            <
updates>
                <
bpgraphics>
                    <
file>bpgraphics.xml</file>
                </
bpgraphics>
            </
updates>
        </
layout>
    </
adminhtml>

The line <action>homepageproduct/adminhtml_testing</action> controls where the link goes to. My folder structure is as follows.

BpGraphics
- HomePageProduct
-- controllers
--- Adminhtml
---- TestingController.php

Am I doing something fundamentally wrong here - I cant seem to find any documentation that makes any real sense and online examples although good do not really explain much.

===== ADDITIONAL

I have also got two files for the adminhtml layout and template these reside in

app/design/adminhtml/default/bpgraphics/template/testing.phtml
app/design/adminhtml/default/bpgraphics/layout/bpgraphics.xml


Would be greatful for any help.

i am too new to magento and had tested the helloworld example. here is what i would like you to test. can you remove the lines below and then clear cache and reload the FE to see if you get the default layout loaded?

<layout>
<updates>
<bpgraphics>
<file>bpgraphics.xml</file>
</bpgraphics>
</updates>
</layout>

 
Magento Community Magento Community
Magento Community
Magento Community
 
Asad Rahman
Jr. Member
 
Avatar
Total Posts:  22
Joined:  2009-04-08
 

HI,

Everything seems correct !!! If you are using linux server then mixed case folder name may create a problem. For example avoid “HomePageProduct” this sort of folder naming. Use “Homepageproduct”. In my early megento days I had faces similar problem in my linux server. I think it will work.

Please let me know what happens grin

Asad
http://magentocookbook.wordpress.com/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Clark Studios
Jr. Member
 
Total Posts:  4
Joined:  2009-05-20
 

Ok Guys Awesome help there and a success. I went with the module creator in the end though. Ok so Stage 1 complete now to Stage 2. I have to say this system has got to be one of the most complex things ever to extend. I am having real issues with it.

Anyone who could try and shed some light on my next problem?

Ok So all set up now what I basically want to do is have a form with a couple of fields placed in it that will update a database. Also when you visit the section later the form is already populated with the values from the database.

A couple of questions, I dont want a grid layout when you visit my module in the back end Just want a form with a couple of fields so I have the following:

class Bpgraphics_Easyhomepage_Block_Adminhtml_Easyhomepage_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{

  
protected function _prepareForm()
  
{

      $form 
= new Varien_Data_Form();
      
$this->setForm($form);
      
// CREATE A FIELDSET TO HOUSE THE FIELDS
     
$fieldset $form->addFieldset('easyhomepage_form', array('legend'=>Mage::helper('easyhomepage')->__('Item information')));
     
      
// ADD A FIELD TO A THE FIELDSET 
      
$fieldset->addField('title''text', array(
          
'label'     => Mage::helper('easyhomepage')->__('Primary Product'),
          
'class'     => 'required-entry',
          
'required'  => true,
          
'name'      => 'primary-product',
      ));
         
     
      if ( 
Mage::getSingleton('adminhtml/session')->getEasyhomepageData() )
      
{
          $form
->setValues(Mage::getSingleton('adminhtml/session')->getEasyhomepageData());
          
Mage::getSingleton('adminhtml/session')->setEasyhomepageData(null);
      
elseif ( Mage::registry('easyhomepage_data') ) {
          $form
->setValues(Mage::registry('easyhomepage_data')->getData());
      
}
      
return parent::_prepareForm();
  
}
}

Ok so that shows and I have calle it Form.php (Can tell by my class name). My next question is how to I iniate the postback and insert the field value into the database. I am struggling with this, and am on the verge of abandoning it, but wont give up without a fight. The books I have are nigh on useless and the only way I have found to try and learn this is to dive head first.

##################### UPDATE

Ok looks like i can connect by using

$collection = Mage::getModel(’easyhomepage/easyhomepage’)->getCollection();

However I am getting an error of

Fatal error: Call to a member function setData() on a non-object in C:\wamp\www\www.magnetotest.co.uk\hosting\webroot\app\code\core\Mage\Adminhtml\Block\Widget\Form\Container.php on line 129

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top