Wednesday, October 7, 2015

Magento - My first simple module to print "Hello Aftab !"

Magento - My first simple module to print "Hello Aftab !"

Step 1.
Create: app/etc/modules/Aftab_Hello.xml
put:
<?xml version="1.0"?>
<config>
    <modules>
        <Aftab_Helloaftab>
        <active>true</active>
        <codePool>local</codePool>
        </Aftab_Helloaftab>
    </modules>
</config>

Step2.
Create: app/code/local/Aftab/Helloaftab/config.xml
Put:
<?xml version="1.0"?>
<config>
    <modules>
        <Aftab_Helloaftab>
            <version>0.1.0</version>
        </Aftab_Helloaftab>
    </modules>
    <frontend>
        <routers>
            <helloaftab>
                <use>standard</use>
                <args>
                    <module>Aftab_Helloaftab</module>
                    <frontName>helloaftab</frontName>
                </args>
            </helloaftab>
        </routers>
       
        <layout>
            <updates>
                <helloaftab>
                    <file>helloaftab.xml</file>
                </helloaftab>
            </updates>
        </layout>
    </frontend>
    <global>
            <blocks>
                <helloaftab>
                    <class>Aftab_Helloaftab_Block</class>
                </helloaftab>
            </blocks>
    </global>
</config>

Step3.
Create: app/code/local/Aftab/Helloaftab/controllers/IndexController.php
Put:
<?php
class Aftab_Helloaftab_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        //echo "Hello Aftab !";
        $this->loadLayout();
        $this->renderLayout();
    }
   
    public function arshadAction()
    {
        //echo "Hello  Arshad !";
        $this->loadLayout();
        $this->renderLayout();
    }
}

Step 4.
Create: app/code/local/Aftab/Helloaftab/Block/helloaftab.php
Put:
<?php
class Aftab_Helloaftab_Block_Helloaftab extends Mage_Core_Block_Template
{
   
}

Step 5.
Create: app/design/frontend/YOUR_THEME_PACKAGE/YOUR_THEME/layout/helloaftab.xml
Put:

<?xml version="1.0"?>
<layout version="0.1.0">
    <helloaftab_index_index>
        <reference name="content">
            <block type="helloaftab/helloaftab" name="helloaftab" template="helloaftab/helloaftab.phtml" />
        </reference>
    </helloaftab_index_index>
</layout>

Step 6.
Create: app/design/frontend/YOUR_THEME_PACKAGE/YOUR_THEME/template/helloaftab/helloaftab.phtml
Put:
<?php echo "Hello Aftab !"; ?>


Step 7.

http://you-site-url/helloaftab/index/
Or http://you-site-url/helloaftab/index/index


Thursday, October 1, 2015

Wordpress-Using wpdb to connect to a separate database

$mydb = new wpdb('username','password','database','localhost');
$rows = $mydb->get_results("select Name from my_table");
echo "<ul>";
foreach ($rows as $obj) :
   echo "<li>".$obj->Name."</li>";
endforeach;
echo "</ul>";