Friday, May 17, 2013

how to Create a simple custom module in magento

Step 1-> Go to app/etc/modules/
Create Fido_All.xml file and paste below code


<?xml version="1.0"?>
<config>
<modules>
<Fido_Example>
<active>true</active>
<codePool>local</codePool>
</Fido_Example>
</modules>
</config>

Step 2-> Go to app/code/local/Fido/Example/etc/
Create a new file config.xml  and paste below code


<?xml version="1.0"?>
<config>
<modules>
<Fido_Example>
<version>0.1.0</version>
</Fido_Example>
</modules>
<global>
<blocks>
<fido_example>
<class>Fido_Example_Block</class>
</fido_example>
</blocks>
</global>
</config>

Step 3-> app\code\local\Fido\Example\Block\
Create a new file  View.php and paste below code


<?php

class Fido_Example_Block_View extends Mage_Core_Block_Template
{
private $message;
private $att;

protected function createMessage($msg) {
$this->message = $msg;
}

public function receiveMessage() {
if($this->message != '') {
    return $this->message;
} else {
  $this->createMessage('Hello World');
  return $this->message;
}
}

protected function _toHtml() {
$html = parent::_toHtml();

if($this->att = $this->getMyCustom() && $this->getMyCustom() !='') {
  $html .= '<br />'.$this->att;
} else {
   $html .= '<br />No Custom Attribute Found';
}

return $html;
}
}

Step 4> app\design\frontend\default\fido\template\example\
Create a new file view.phtml  and paste below code
.

<div>
<span><strong>This is the output of the fido example:</strong></span><br />
<span style="color:#FF9933;">
<?php
echo $this->receiveMessage();
?>
</span>
</div>



No comments:

Post a Comment