Magento : How to Create Controller in Magento

In This article we will discuss how to create controller in magento module controller. Controller is used to communicate between Model and View, For example we want to create a new group of controller class under a mymodule controller folder.
My Module folder structure is:

mymodule/controllers/indexControler.php

We will create new folder ‘render’ under mymodule controller folder and now create new controller class under newly created folder.

mymodule/controllers/rednder/carusalController.php

Then url would be new controller action :

mywebsite/module_name/controller_render/action

You can also check other tutorial of magento,

Step 1: First we will create a controller(renderContrioller.php) file under controllers folder.

Select Code
1
mymodule/controllers/renderController.php

Step 2: Write below code in above created file.

Select Code
1
2
3
4
5
6
<?php  
class NS_MN_RenderController extends Mage_Core_Controller_Front_Action  
{  
      
}  
?>

Step 3: We will create folder 'render' same name as above controller file created.

mymudle/controllers/render

Step 4: We will create Carousel controller under render folder.

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
<?php  
class NS_MN _Render_CarouselController extends Mage_Core_Controller_Front_Action  
{  
     /** 
     * Get test of particular static block 
     */  
    public function indexAction()  
    {  
        $this->loadLayout();  
        $this->renderLayout();  
    }  
}