Category: PHP


Magento Module Tutorial

This tutorial is taken from http://blog.baobaz.com/en/blog/magento-module-create-your-own-controller, So please go there if you want see more info i just makes my own backup :)

Magento is based on MVC model. This model helps for defining models, view (layout + templates) and controllers. Despite big amount of modules available by default in Magento and on Magento Connect, you may want to create your own module and define your controller for you Magento website. No problem, this tutorial will explain you how to create your own controller and how to make it respect its authoritah to layouts and templates.

Purpose of this example controller will be to give result of two integers multiplication (very useful if you lost your calculator). Integers will be provided through a basic form. Result will be displayed in a Magento notification.

Before starting creation of your module, please turn off the cache management in order to see immediately every change.

Creating your module

Our extension will be named arithmetic. Folders needed for this extension are created.

$ mkdir -p app/code/local/Baobaz/Arithmetic/controllers
$ mkdir -p app/code/local/Baobaz/Arithmetic/etc

We create file app/code/local/Baobaz/Arithmetic/etc/config.xml, in order to register this extension

<?xml version=“1.0″ encoding=“UTF-8″?>
<config>
    <modules>
        <baobaz_arithmetic>
            <version>0.0.1</version>
        </baobaz_arithmetic>
    </modules>
</config>

And a file app/etc/modules/Baobaz_Arithmetic.xml for its activation:

<?xml version=“1.0″ encoding=“UTF-8″?>
<config>
    <modules>
        <Baobaz_Arithmetic>
            <active>true</active>
            <codePool>local</codePool>
        </Baobaz_Arithmetic>
    </modules>
</config>

For more informations about creation of a new extension, please check Wojtek‘s post “Developing module for Magento Tutorial – Where to Begin [Part 1]“.

Creating a controller

You need now to create file app/code/local/Baobaz/Arithmetic/controllers/IntegerController.php and write method that will be used for multiplication.

Controller files must always follow pattern xxxxxController.php (xxxxx will be used after in url for calling this controller) and put in controllers folder.
Controllers methods names must follow pattern yyyyyAction (yyyyy will also be used in url for calling this controller). For the moment content of our file is:

class Baobaz_Arithmetic_IntegerController extends Mage_Core_Controller_Front_Action
{
    public function multiplyAction(){
    }
}

We need to indicate now that some controllers are available in Arithmetic modules. For doing that, we add the following content in app/code/local/Baobaz/Arithmetic/etc/config.xml file:

<config>
    …
    <frontend>
        <routers>
            <arithmetic>
                <use>standard</use>
                <args>
                    <module>Baobaz_Arithmetic</module>
                    <frontName>arithmetic</frontName>
                </args>
            </arithmetic>
        </routers>  
    </frontend>
</config>

Let see how this router declaration works:

  • indicates that router will be use in front part of website
  • is where you declare all your routers
  • is identifier of this router
  • standard can take value standard (for front part) or admin (for admin part).
  • Baobaz_Arithmetic indicates which module contain controller that handles this router
  • arithmetic is router name that will be used in url

We can now modify multiplyAction method for making it displaying a message:

public function multiplyAction(){
    echo “Respect my authoritah”;
}

When you call now url http://monsitemagento/arithmetic/integer/multiply message “Respect my authoritah” will be displayed. Let dissect this url:

  • arithmetic tells that controller is in Baobaz_Arithmetic module
  • integer tells that controllers/integerController.php file must be cehcked
  • multiply tells that multiplyAction method must be chosen in this file

Displaying a template

We define which layout file will be used in the module:

<config>
    …
    <frontend>
        …
        <layout>
            <updates>
                <arithmetic>
                    <file>arithmetic.xml</file>
                </arithmetic>
            </updates>
        </layout>
    </frontend>
</config>

We create app/design/frontend/default/default/layout/arithmetic.xml file in order to define which blocks will be used for controller that was just made.

<?xml version=“1.0″ encoding=“UTF-8″?>
<layout version=“0.1.0″>
    <arithmetic_integer_multiply>
        <reference name=“root”>
            <action method=“setTemplate”>
                <template>page/1column.phtml</template>
            </action>
        </reference>
        <reference name=“content”>
            <block type=“core/template” name=“arithmetic_integer_multiply” template=“arithmetic/integer/multiply.phtml”></block>
        </reference>
    </arithmetic_integer_multiply>
</layout>

Main template used by arithmetic/integer/multiply is page/1column.phtml. For “content” part of this template, only arithmetic_integer_multiply block will be displayed. This block does not need any particular management. It is then set with core/template type that is default type. Template file used will be arithmetic/integer/multiply.phtml.

Our template is defined, app/design/frontend/default/default/template/arithmetic/integer/multiply.phtml must then be created. This file will be empty for the moment..

For displaying correctly layout, it must be loaded in controller

public function multiplyAction(){
    $this->loadLayout();
    $this->renderLayout();
}

Interaction between template and controller

Our template will just have a basic form for providing integers to multiply

<form action=” method=”post”>
    <fieldset>
        <ul>
            <li>
                <label for=“int1″>Integer 1</label>
                <input type=“text” id=“int1″ name=“int1″ />
            </li>
            <li>
                <label for=“int2″>Integer 2</label>
                <input type=“text” id=“int2″ name=“int2″ />
            </li>
            <li><input type=“submit” value=“Multiply” /></li>
        </ul>
    </fieldset>
</form>

Action form url is again arithmetic/integer/multiply. Controller action must then be modified in order to manage data from form and to give result.

public function multiplyAction(){
    if ($this->getRequest()->isPost()){
        $int1 = $this->getRequest()->getPost(‘int1′);
        $int2 = $this->getRequest()->getPost(‘int2′);
        $result = $int1 * $int2;
    Mage::getSingleton(‘customer/session’)->addSuccess($int1 * $int2 = $result);
    }
    $this->loadLayout();
    $this->_initLayoutMessages(‘customer/session’);
    $this->renderLayout();
}

In order to know if controller is called after using form, following instruction is used:

$this->getRequest()->isPost()

Result is put in ‘customer/session’ session. For being able to display this result in template, message template must be loaded in multiplyAction method:

$this->_initLayoutMessages(‘customer/session’);

Add then in you template the following line where you want to display the result

echo $this->getMessagesBlock()->getGroupedHtml();

And here we are: we have now a new controller that displays result of a multiplication.

Speed up your store by combining, compressing and caching JS and CSS. The extension  ( Fooman Speedster )reworks how Magento handles the loading of JavaScript and CSS. It utilises the Minify library developed by Steve Clay and released under a BSD license.

Fooman Speedster

View full article »

Magento Admin menus not work some times?

Change the permissions of the folder “js” and the file “js/proxy.php” to 755 fixes the problem.

if still not wok then.. http://www.magentocommerce.com/boards/viewthread/4679/P30/#t17628 by Scend

For Beginner working with magento theme for the first time some times confuse the developer when categories are not shown.

Go : admin->Catalog->Manage Categories  and select your root category and make sub-categories.

if you change the root categories then Make sure that ROOT is the “Root Category” of your site

You can check it in Admin > System > Manage Store > Edit Store

You need to read more about categories :)

http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-and-managing-categories

after adding a product it, still not shown.??? ——-ok you should confirm that the product inventory In-Stock is selected, ant the quantity also :D … its bit confusing but once you get the problem … no hassle for future..

clear cache from admin->system->cache management : : to check the recent update… you can download Magento Developer toolbar also for quick cache clear :)

Zend Framework Coding Standard for PHP

Many developers using Zend Framework have also found these coding standards useful because their code’s style remains consistent with all Zend Framework code. It is also worth noting that it requires significant effort to fully specify coding standards. ….. View full article »

Few wOrDpReSs tips

Template Tags/query posts

if (window.showTocToggle) { var tocShowText = “show”; var tocHideText = “hide”; showTocToggle(); }

Description

Query_posts can be used to control which posts show up in The Loop. It accepts a variety of parameters in the same format as used in your URL (e.g. p=4 to show only post of ID number 4).

Why go through all the trouble of changing the query that was meticulously created from your given URL? You can customize the presentation of your blog entries by combining it with page logic (like the Conditional Tags) — all without changing any of the URLs.

Common uses might be to:

  • Display only a single post on your homepage (a single Page can be done via Settings -> Reading).
  • Show all posts from a particular time period.
  • Show the latest post (only) on the front page.
  • Change how posts are ordered.
  • Show posts from only one category.
  • Exclude one or more categories.

Important note

The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should create separate WP_Query objects and use those instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.

The query_posts function overrides and replaces the main query for the page. To save your sanity, do not use it for any other purpose.

Usage

Place a call to query_posts() in one of your Template files before The Loop begins. The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the variable $query_string in the call to query_posts().

For example, to set the display order of the posts without affecting the rest of the query string, you could place the following before The Loop:

query_posts($query_string . "&order=ASC")

When using query_posts in this way, the quoted portion of the argument must begin with an ampersand (&).

View full article »

http://www.ning.com
Try this …I do believe you like this…

Visit http://ilovemybangladesh.ning.com for bangladeshi lovers social network created by me.

Pligg, The Open Source Digg Clone

Pligg is an open source Content Management System (CMS) available to download for free. Pligg has perfected content management in a unique way that encourages users to participate and control the content on the site. This makes the site user-moderated and allows for “social publishing” where the stories are created and promoted by members not website editors. Pligg CMS is based on PHP and MySQL technologies that allow it to be installed on almost any web host on a relatively small budget. For support please visit the Pligg Forum where you can find help 24 hours a
day thanks to our excellent development team and contributors. Pligg is free software, but you are welcome
to donate any amount by clicking the button below.

WordPress Coding Standards

WordPress Coding Standards

Some legacy parts of the WordPress code structure for PHP markup are inconsistent in their style. WordPress is working to gradually improve this by helping users maintain a consistent style so the code can remain clean and easy to read at a glance.
View full article »

You think how….yes i was also..then www.oDesk.com…Make that true..i refer my friends to oDesk and then they earn money at oDesk and oDesk referral program give me $$$. Its really like…getting some free $$$ by your friends…so do start it right now and start refer all your friends who are great to work online and you know who can earn money fast on oDesk…Its really simple ..you can just signup and start working by your self too….

We have lots of friends …like facebooks/myspace/hi5 etc we have lots of friends…so if we try then we can do a better network with oDesk and our friends….we all want to earn at the same times…as you know we are friends and friendship is the great relation in this world….a true friends can do a lot for you…

All right…i am going to refer …..one of my friends right now…so i have no time to write more on this post….hahahaha….c ya later post…

Bye
Thanks
Regards
shahin

Outsource to Freelancers, IT Companies, Programmers, Web Designers from India, Russia, USA, and more Certified Professionals. Verified Work.

oDesk My Office/Heaven

Hi,
I work at oDesk…you see i got a heaven at earth? :( don’t you believe me..???? ok just signup and test oDesk …i swear if you have little patient and if you interested to earn from home…test heaven happyness then .:) believe me…signup and start apply oDesk job. Give oDesk tests to increase your job quota.

Ohh You want to post a job….No worry…you come at right place …oDesk is the best place where you can get the planet best service from a 10000000000million talents at this planet…you confuse????Oh ok man just go to odesk and post a job….and dont forgot to email me…if i am right…

The On Demand Global Workforce - oDesk

Oh…you want to hire me…all right …just click me

The On Demand Global Workforce - oDesk

I would like you see at odesk soon….

Thanks

shahin

shahinbdboy@gmail/yahoo.com

Do you like to play tennis

http://www.creatiu.com/tennis/tennis.php?language=en

play and save your name and score….

Action script with php work… for creatiu project

Experience

I do work on php for many years, i use codeigniter,ajax,mysql,Pligg,wordpress,smarty,zend FW etc.

Follow

Get every new post delivered to your Inbox.