Add a new Module “Hello World” In magento!!

I only success until to day as only a module added that is just pass a massage from block to front end.
It has also some bug. But i want to share to all and need help to find out how can i add some core code here that will be like as original magento Module.

1. At first i make a folder in \app\code\local folder named as Liveoutsource. Where i would make the core code.
In here i make a folder named \app\code\local\Liveoutsource\etc and make a config.xml file and write these code here

<?xml version="1.0"?>
<config>
	<modules>
		<Liveoutsource_Example>
			<version>0.7.2</version>
		</Liveoutsource_Example>
	</modules>
<global>
	<blocks>
		<example><class>Example_Block</class></example>
	</blocks>
</global>
</config

It is the config file that config the module.

2. then \app\code\local\Liveoutsource\Block add a file named View.php

<?php
/**
* Example View block
*
* @codepool   Local
* @category   Liveoutsource
* @package    Liveoutsource_Example
* @module     Example
*/
class Liveoutsource_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();

//return $html;
}
} 

3. \app\design\frontend\default\default\template add a folder example and add a file view.phtml and add these code here.

?php

/**
* Liveoutsource view template
*
* @see Liveoutsource_Example_Block_View
*
*/
?>
<div>
<span><strong>This is the output of the Liveoutsource example:</strong></span><br />
<span style="color:#FF9933;">
<?php
echo $this->receiveMessage();
?>

</span>
</div>

4. add the code here \app\etc\modules\Liveoutsource_All.xml

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

5. then add these code where u want to see it

<div style="border: 1px thick #FF0000;">
					<?php echo $this->getLayout()->createBlock('Example/View')->setTemplate('example/view.phtml')->toHtml(); ?>
				
					</div>
Advertisements

Tagged: ,

One thought on “Add a new Module “Hello World” In magento!!

  1. strategie für roulette January 13, 2010 at 6:03 am

    Great idea, thanks for this tip!

Comments are closed.

%d bloggers like this: