How to Override Controller file in magento?

How to Override Controller file in magento:
In this post, will see how to override controller file in magento. Basically we need to do following steps to override a controller file.
here will see how to override the checkout controller file.

Step: 1 Override you module xml file
app/etc/modules/Jute_Checkout.xml
<?xml version=”1.0″?>
<config>
<modules>
<Jute_Checkout>
<active>true</active>
<codePool>local</codePool>
</Jute_Checkout>
</modules>
</config>

Step: 2
Override you controller file. Which one you want override.Copy the CartController.php file from your base folder and replace to you local.
Copy from base\Checkout\controllers\CartController.php Paste into “local”. Here am overriding addAction function.Which function you want you override. Don’t copy entire functions (unless if required or not)

require_once ‘Mage/Checkout/controllers/CartController.php’;
class Jute_Checkout_CartController extends Mage_Checkout_CartController
{
public addAction()
{
}
}

Step: 3
Create config.xml file into you “local/Jute/Checkout” folder. Checkout below frontend node is required for override a controller file.
Config.xml
<?xml version=”1.0″?>
<config>
<modules>
<Jute_Checkout>
<version>0.0.1</version>
</Jute_Checkout>
</modules>
<global>
….
</global>

<frontend>
<routers>
<checkout>
<args>
<modules>
<jute_checkout before=”Jute_Checkout”>Jute_Checkout</jute_checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

Step: 4
Clear cache. And check, it will work.

Note:
Above we are override Checkout controller. In some case, you have to create you own controller, then follow like below
Front End Controller:
Step: 1 Create you controller file like below
class Jute_Mymodule_MyController extends Mage_Core_Controller_Front_Action
{
}

Step: 2
Config file is like below
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>Jute_Mymodule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
<frontend>

If Admin Controller:
class Jute_Mymodule_Adminhtml_MyController extends Mage_Adminhtml_Controller_Action
{
}