Posted by: james | July 11, 2009

Create sipmle first custom module in magento..

Note: ” Always rememeber do not change any file which is in app folder of magento, always create new folder,file in local folder”.
so go to app/code/local
and create here new folder called Example and in that create new folder First. so our folder structure will look like this
app/code/local/Example/First
in that create new folder etc and in that create new config.xml file.
app/code/local/Example/First/etc/config.xml and now write in that,

<?xml version=”1.0″ encoding=”UTF-8″?>

<config>
<modules>
<Example_First> // here always use name as you give to folder and also maintaine the cases for uppercase or lowercase and if you have

<version>0.1.0</version>  not nested folder then you can direct just put one folder name.. like <Example> </Example>
</Example_First>
</modules>

// now time to defien all other folders like model,blocks,etc….. so, for that

//for blocks

<global>
<blocks>
<Example_First>
<class> Example_First_Block </class> // now when we create new .php file in block folder then its class prefix will be always

this and after that your file name.. for ex. if we create file view.php in block

folder then its class name will be Example_First_Block_view extends another class name….
</Example_First>
</blocks>
</global>

//for model

<global>
<models>
<Example_First>
<class> Example_First_Model </class> // now when we create new .php file in model folder then its class prefix will be always

this and after that your file name.. for ex. if we create file view.php in block

folder then its class name will be Example_First_Model_view extends another class name….
</Example_First>
</blocks>
</global>

</config>

Now this config file has finished now move to another step….

Now go to app/etc/modules create new xml file and give name relate to your extension.
ex. i give name Example_All.xml

in that write this

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Example_First>
<active> true </active> // after this you module will display at admin side, to see it go to admin panel and in that

System->configuration->Advanced
<codePool> local </codePool>
</Example_First>

</modules>
</config>

Now create new folder Block in First folder so our fodler structure will look like this
app/code/local/Example/First/Block and in that create new .php file i have created View.php so, now
app/code/local/Example/First/Block/view.php now write in that

class Example_First_Block_View extends Mage_Core_Block_Template
{
public function doSomeAction()
{
$msg = “Hi, this is first Extension”;
return $msg;
}
}

Now our module has been created at admin side but to display it at frontendside go to
app/design/frontend/default/default/template/example/view.phtml
// here see name convention the example will come in small case .
now write in view.phtml
<div> Output of our Effort </div>

echo ‘Class Name:<strong>’.get_class($this).'</strong>’;
echo $this->doSomeAction();

// now we have to decide that in which page we want to display it as this is our first ex. we will display it at cms page. so go to admin

panel and in that CMS/Manage PAges and click on home page.. so it will open now in content write this at any place..

<div><h1> Sample Message of our effort: </h1>
{{block type=”Example_First/view” template=”example/view.phtml”}}</div>

Advertisements

Responses

  1. I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks, 🙂

    A definite great read.. ..

    -Bill-Bartmann


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: