Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:03:02+00:00 2026-05-11T07:03:02+00:00

How can the following be accomplished in Magento? Display a Hello World message using

  • 0

How can the following be accomplished in Magento?

  • Display a ‘Hello World’ message using a controller/view/model approach. So, if I went to http://example.com/myController it would show the string ‘Hello World’. Being able to show this string within the template of my website (for example, the header, footer, etc.) will be a bonus.

  • How do I add a method to this controller (or a new controller if necessary), which interacts with a model, and performs the query Select * FROM articles where id='10' and returns the row (containing the columns id, title, content) to the controller? And then use the controller to include a view, which would display this row. So going to http://example.com/myController/show_row (or something similar) would display the row within a view. (No need to be fancy, just a echo $row->id; or something similar would work.)

Any other information about Magento’s code structure will also be very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:03:03+00:00Added an answer on May 11, 2026 at 7:03 am

    First and foremost, I highly recommend you buy the PDF/E-Book from PHP Architect. It’s US$20, but is the only straightforward ‘Here’s how Magento works’ resource I’ve been able to find. I’ve also started writing Magento tutorials at my own website.

    Second, if you have a choice, and aren’t an experienced programmer or don’t have access to an experienced programmer (ideally in PHP and Java), pick another cart. Magento is well engineered, but it was engineered to be a shopping cart solution that other programmers can build modules on top of. It was not engineered to be easily understood by people who are smart, but aren’t programmers.

    Third, Magento MVC is very different from the Ruby on Rails, Django, CodeIgniter, CakePHP, etc. MVC model that’s popular with PHP developers these days. I think it’s based on the Zend model, and the whole thing is very Java OOP-like. There’s two controllers you need to be concerned about. The module/frontName controller, and then the MVC controller.

    Fourth, the Magento application itself is built using the same module system you’ll be using, so poking around the core code is a useful learning tactic. Also, a lot of what you’ll be doing with Magento is overriding existing classes. What I’m covering here is creating new functionality, not overriding. Keep this in mind when you’re looking at the code samples out there.

    I’m going to start with your first question, showing you how to setup a controller/router to respond to a specific URL. This will be a small novel. I might have time later for the model/template related topics, but for now, I don’t. I will, however, briefly speak to your SQL question.

    Magento uses an EAV database architecture. Whenever possible, try to use the model objects the system provides to get the information you need. I know it’s all there in the SQL tables, but it’s best not to think of grabbing data using raw SQL queries, or you’ll go mad.

    Final disclaimer. I’ve been using Magento for about two or three weeks, so caveat emptor. This is an exercise to get this straight in my head as much as it is to help Stack Overflow.

    Create a module

    All additions and customizations to Magento are done through modules. So, the first thing you’ll need to do is create a new module. Create an XML file in app/modules named as follows

    cd /path/to/store/app touch etc/modules/MyCompanyName_HelloWorld.xml 
    <?xml version='1.0'?> <config>      <modules>         <MyCompanyName_HelloWorld>             <active>true</active>             <codePool>local</codePool>         </MyCompanyName_HelloWorld>      </modules> </config> 

    MyCompanyName is a unique namespace for your modifications, it doesn’t have to be your company’s name, but that the recommended convention my magento. HelloWorld is the name of your module.

    Clear the application cache

    Now that the module file is in place, we’ll need to let Magento know about it (and check our work). In the admin application

    1. Go to System->Cache Management
    2. Select Refresh from the All Cache menu
    3. Click Save Cache settings

    Now, we make sure that Magento knows about the module

    1. Go to System->Configuration
    2. Click Advanced
    3. In the ‘Disable modules output’ setting box, look for your new module named ‘MyCompanyName_HelloWorld’

    If you can live with the performance slow down, you might want to turn off the application cache while developing/learning. Nothing is more frustrating then forgetting the clear out the cache and wondering why your changes aren’t showing up.

    Setup the directory structure

    Next, we’ll need to setup a directory structure for the module. You won’t need all these directories, but there’s no harm in setting them all up now.

    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 configuration file

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

    and inside the configuration file, add the following, which is essentially a ‘blank’ configuration.

    <?xml version='1.0'?> <config>     <modules>         <MyCompanyName_HelloWorld>             <version>0.1.0</version>         </MyCompanyName_HelloWorld>     </modules> </config> 

    Oversimplifying things, this configuration file will let you tell Magento what code you want to run.

    Setting up the router

    Next, we need to setup the module’s routers. This will let the system know that we’re handling any URLs in the form of

    http://example.com/magento/index.php/helloworld 

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

    <config> <!-- ... -->     <frontend>         <routers>             <!-- the <helloworld> tagname appears to be arbitrary, but by             convention is should match the frontName tag below-->             <helloworld>                 <use>standard</use>                 <args>                     <module>MyCompanyName_HelloWorld</module>                     <frontName>helloworld</frontName>                 </args>             </helloworld>         </routers>     </frontend> <!-- ... --> </config> 

    What you’re saying here is ‘any URL with the frontName of helloworld …

    http://example.com/magento/index.php/helloworld 

    should use the frontName controller MyCompanyName_HelloWorld’.

    So, with the above configuration in place, when you load the helloworld page above, you’ll get a 404 page. That’s because we haven’t created a file for our controller. Let’s do that now.

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

    Now try loading the page. Progress! Instead of a 404, you’ll get a PHP/Magento exception

    Controller file was loaded but class does not exist 

    So, open the file we just created, and paste in the following code. The name of the class needs to be based on the name you provided in your router.

    <?php 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’ve just setup is the module/frontName controller. This is the default controller and the default action of the module. If you want to add controllers or actions, you have to remember that the tree first part of a Magento URL are immutable they will always go this way http://example.com/magento/index.php/frontName/controllerName/actionName

    So if you want to match this url

    http://example.com/magento/index.php/helloworld/foo 

    You will have to have a FooController, which you can do this way :

    touch app/code/local/MyCompanyName/HelloWorld/controllers/FooController.php 
    <?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';     } } 

    Please note that the default controller IndexController and the default action indexAction can by implicit but have to be explicit if something come after it. So http://example.com/magento/index.php/helloworld/foo will match the controller FooController and the action indexAction and NOT the action fooAction of the IndexController. If you want to have a fooAction, in the controller IndexController you then have to call this controller explicitly like this way : http://example.com/magento/index.php/helloworld/index/foo because the second part of the url is and will always be the controllerName. This behaviour is an inheritance of the Zend Framework bundled in Magento.

    You should now be able to hit the following URLs and see the results of your echo statements

    http://example.com/magento/index.php/helloworld/foo http://example.com/magento/index.php/helloworld/foo/add http://example.com/magento/index.php/helloworld/foo/delete 

    So, that should give you a basic idea on how Magento dispatches to a controller. From here I’d recommended poking at the existing Magento controller classes to see how models and the template/layout system should be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
Can some professional experienced Magento developer tell me how to accomplish the following in
The following event can possibly get called hundreds of times a frame. public bool
In Firefox you can enter the following into the awesome bar and hit enter:
In PHP I can do the following: $myVar = 'name'; print $myClass->$myVar; // Identical
Does anyone know how I can achieve the following effect in OpenGL: Change the
I would like to do something like the following but can't seem to get
I like that in PHP I can do the following $myInteger++; $myString += 'more
When calling CoInitializeEx , you can specify the following values for dwCoInit : typedef
According to what I have found so far, I can use the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.