Controller Font Magento

Cocoa has been delayed for some time, because I hang code to pay the bill on hold. I have the Magento e-commerce system with a lot recently, and thought I would share. Here is my answer from a stack overflow problem.

Great product and excellent customer support! Excellent price, prompt shipping, fair shipping price, and delivery right on schedule. Cialis perscription online? Our pharmacy is the leader in delivering medications throughout the world.

How Magento code work?

Compared to others on the market, best price and quality. Buy viagra for women. You can buy branded and generic medicines.

First of all, I strongly recommend you buy the PDF / E in the book from PHP architects. This is 20 yuan, and the only straight forward, “This is how Magento works” I have been able to find the resources.

Second, if you have a choice, not an experienced programmer / not have access to experienced programmers, located in the PHP and Java (), select the other car. Magento is a well-designed, but its design will be a shopping cart solution, other programmers can build on top of the module. It is not designed to be easy to understand who is smart, but not a programmer.

Third, Magento MVC is very different bar / Django in the / code ignition / cake / etc PHP MVC pattern these days developers welcome. I think this is Zend’s model, the whole thing is an object-oriented Java class. There are two controllers you need to concern. The module / frontName controller, then the MVC controller.

Fourth, Magento application itself is using the same modular system, you will use, so poke around the core code is a useful learning strategy. In addition, what you will do a lot with Magento is an overriding existing classes. What I would like to create a new cover feature, and not overwhelming. Remember that when you are looking at the code samples.

I want to start your first question, to show you how to set up a controller / router to respond to a specific URL. This will be a small novel. I will have time after the model / template-related topics, but now, I do not know. I will, but simply to your SQL questions.

Magento using the EAV database structure. Whenever possible, try to use the system object model to get the information you need. I know that nothing in the SQL table, but do not grab the data that the use of the original SQL query, or you will go crazy.

Final statement. I’ve been using for about two or three weeks, so caveat emptor Magento. This is a work, which are directly in my mind as much as it is to help StackOverflow.

Create a Module

Magento through all the supplements and custom module. So, first you need to do is create a new module. Create an XML file in app / modules are named

cd /path/to/store/app
touch etc/modules/MyCompanyName_HelloWorld.xml  

<?xml version="1.0"?>   <config>

MyCompanyName is your only namespace changes, it does not become your company’s name, but my proposed convention magento. Is your name HelloWorld module.

Clear the Application Cache

Now, place the module file, we need to magento to know it (and check our work). In Management

1. Go to System> Cache Management
2. Select from all the cache refresh menu
3. Click the Save Cache Settings

Now we know the module to ensure magento

1. Go to System> “Configuration
2. Click the Advanced
3. In the “Disable the module output” setting box for your new name “MyCompanyName_HelloWorld module to see”

If you can slow down the performance live, you may want to close the application cache, and developing / learning. Nothing is more frustrating then forget the cache clear and wondering why your changes are not displayed.

Setup the Directory Structure

Next, we need to set a module’s directory structure. You do not need all of these directories, but did not put them all in the formulation of the present injury.

mkdir -p app/code/local/MyCompanyName/HelloWorld
mkdir -p app/code/local/MyCompanyName/HelloWorld/Block
mkdir -p app/code/local/MyCompanyName/HelloWorld/controllers
mkdir -p app/code/local/MyCompanyName/HelloWorld/Model
mkdir -p app/code/local/MyCompanyName/HelloWorld/Helper
mkdir -p app/code/local/MyCompanyName/HelloWorld/etc
mkdir -p app/code/local/MyCompanyName/HelloWorld/sql

And add a profile

touch app/code/local/MyCompanyName/HelloWorld/etc/config.xml

And internal configuration file, add the following, essentially a “blank” configuration.

<?xml version="1.0"?>   <config>    

Simplify things, the configuration file allows you to tell which code to run Magento.

Setting up the Router

Next, we need to set the router module. This will let the system know that we are dealing with any form of web site

So, in your configuration file, add the following section.

<!-- ... -->
            <!-- the <helloworld> tagname appears to be arbitrary, but by 
            convention is should match the frontName tag below-->
<!-- ... -->        

What you say here is, “any websites HelloWorld frontName …

Should be used frontName controller MyCompanyName_HelloWorld “.

Thus, with the place, when you load the HelloWorld page 100 above configuration, you will get a 404 page. This is because we have not provided us with a controller file. Let us do so.

touch app/code/local/MyCompanyName/HelloWorld/controllers/IndexController.php

Now try to load the page. Progress! Instead of 404, you will get a PHP / Magento exception

Controller file was loaded but class does not exist

Therefore, open the file, we just created and paste the code below. The name of the class need your name in your router provides the basis.

class MyCompanyName_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        echo "We're echoing just to show that this is what's called, normally you'd have some kind of redirect going on here";

What we have just installed the module / frontName controller. This is not the MVC controller. Try the following URL, you will get a 404, even if you have a method in MyCompanyNameHelloWorldIndexController fooAction

Therefore, to install the MVC controller, create a new file, and enter the following code (yes, this also extends MageCoreControllerFrontAction controller, although it is not one aspect of the action. Yes, this is confusing, but I think it is how to do things)

touch app/code/local/MyCompanyName/HelloWorld/controllers/FooController.php
class MyCompanyName_HelloWorld_FooController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        echo 'Foo Index Action';

    public function addAction(){
        echo 'Foo add Action';

    public function deleteAction(){
        echo 'Foo delete Action';

Yo should now be able to play the following URL to see the results of your echo statments

Therefore, this should give you a Magento sent to the controller on how the basic idea. Here, I propose that the existing Magento stamp controller class, take a look at models and the template / layout system should be used.

(Based on Alanstorm Turtorial)