<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpinOneSolutions &#187; Controller</title>
	<atom:link href="http://www.spinonesolutions.com/tag/controller/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.spinonesolutions.com</link>
	<description>I waste my time so that you don't have to...</description>
	<lastBuildDate>Fri, 16 Apr 2010 21:39:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Magento Controller Override</title>
		<link>http://www.spinonesolutions.com/2010/03/magento-controller-override/</link>
		<comments>http://www.spinonesolutions.com/2010/03/magento-controller-override/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 16:00:11 +0000</pubDate>
		<dc:creator>Will Wright</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Override]]></category>

		<guid isPermaLink="false">http://www.spinonesolutions.com/?p=511</guid>
		<description><![CDATA[The Problem: You want to override a Controller&#8217;s action with a custom action. Magento Enterprise v1.6.0.0 The Solution: I ran into some issues trying to override a controller&#8217;s action yesterday. I think it mainly stems from a version change, but at any rate here&#8217;s the &#8220;new&#8221; way to do it. This comes from a helpful [...]]]></description>
			<content:encoded><![CDATA[<h3>The Problem:</h3>
<p>You want to override a Controller&#8217;s action with a custom action.</p>
<p>Magento Enterprise v1.6.0.0</p>
<h3>The Solution:</h3>
<p>I ran into some issues trying to override a controller&#8217;s action yesterday. I think it mainly stems from a version change, but at any rate here&#8217;s the &#8220;new&#8221; way to do it. This comes from a helpful <a href="http://www.magentocommerce.com/boards/viewthread/37244/">post</a> on the Magento forums.</p>
<p>In this example my custom modules&#8217;s namespace is &#8220;Spinonesolutions&#8221; and I&#8217;m going to override the <strong>createPostAction</strong> in <strong>Mage_Customer_AccountController.</strong></p>
<p>Start by creating a bare bones custom module; if you don&#8217;t know how to do this check out <a title="Magento – Part I : Custom Module" href="http://www.spinonesolutions.com/2009/09/magento-custom-module-part-i/">Magento – Part I : Custom Module</a>.</p>
<p>I&#8217;ve only got two files in my custom module; <strong>controllers/AccountController.php</strong> and <strong>etc/config.xml</strong>.</p>
<p>config.xml:</p>
<pre class="php" name="code">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;config&gt;
&lt;modules&gt;
  &lt;Spinonesolutions_Customer&gt;
    &lt;version&gt;0.0.1&lt;/version&gt;
  &lt;/Spinonesolutions_Customer&gt;
&lt;/modules&gt;
&lt;frontend&gt;
  &lt;routers&gt;
    &lt;!-- This is the frontname to override
    EG: http://mydomainname.com/customer/  --&gt;
    &lt;customer&gt;
      &lt;args&gt;
        &lt;modules&gt;
          &lt;!-- Use the module Spinonesolutions_Customer BEFORE Mage_Customer --&gt;
          &lt;Spinonesolutions_Customer before="Mage_Customer"&gt;Spinonesolutions_Customer&lt;/Spinonesolutions_Customer&gt;
        &lt;/modules&gt;
      &lt;/args&gt;
    &lt;/customer&gt;
  &lt;/routers&gt;
&lt;/frontend&gt;
&lt;/config&gt;</pre>
<p>AccountController.php:</p>
<pre class="php" name="code">&lt;?php
/**
* Override Customer AccountController
*
* Override the createPost action
*
* @category Mage
* @package Mage_Customer
* @author Will Wright
*/

/*Controllers aren't included automatically, so we include it here so that we can extend it*/
include_once("Mage/Customer/controllers/AccountController.php");
class Spinonesolutions_Customer_AccountController extends Mage_Customer_AccountController {
  public function createPostAction() {
    die('here');
  }
}</pre>
<p>That&#8217;s it!  You should now have a working override.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.spinonesolutions.com/2010/03/magento-controller-override/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Magento &#8211; Part III : Controllers</title>
		<link>http://www.spinonesolutions.com/2009/10/magento-part-iii-controllers/</link>
		<comments>http://www.spinonesolutions.com/2009/10/magento-part-iii-controllers/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 16:38:05 +0000</pubDate>
		<dc:creator>Will Wright</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Controller]]></category>

		<guid isPermaLink="false">http://www.spinonesolutions.com/?p=392</guid>
		<description><![CDATA[The Problem: I need to write Part III of the Magento series. The Solutions: This article&#8230; TADA! First, let’s talk about the controller.  The default controller for a module is always named IndexController.php.  If you haven’t requested a specific controller (in the URL), than the system is going to look for IndexController.php and load it.  [...]]]></description>
			<content:encoded><![CDATA[<h2>The Problem:</h2>
<p>I need to write Part III of the Magento series.</p>
<h2>The Solutions:</h2>
<p>This article&#8230; TADA!</p>
<p>First, let’s talk about the controller.  The default controller for a module is always named <strong>IndexController.php</strong>.  If you haven’t requested a specific controller (in the URL), than the system is going to look for <strong>IndexController.php</strong> and load it.  Similarly, the default Magento action is <strong>indexAction()</strong>.</p>
<p>Applying this logic to my custom Module; if I simply type {base}/spinonesolutions/ into the address bar, Magento is going to load up <strong>Spinonesolutions_Helloworld_IndexController</strong> and invoke <strong>indexAction()</strong>.  Remember that “spinonesolutions” is the frontname that I defined for this module in the <strong>config.xml</strong> (See <a title="Part II : Models" href="http://www.spinonesolutions.com/2009/10/magento-part-ii-models/">Part II : Models</a> for source).</p>
<pre class="php" name="code">&lt;?php
//IndexController is the default controller
//EG: http://localhost/spinonesolutions/
//Notice there's no parameters being passed as a parameter (Nothing after trailing "/")
//IndexController will be called since it's the default.
//"spinonesolutions" is the frontname as defined in confg.xml
class Spinonesolutions_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {
      //indexAction is the default Action for any controller
      function indexAction() {
            echo "indexAction";
            $helloworld = Mage::getModel("spinonesolutions_helloworld/helloworld");
            $helloworld-&gt;helloworld("helloworld");
      }
}</pre>
<pre class="xml" name="code">&lt;?xml version=<em>"1.0"</em> encoding=<em>"UTF-8"</em> ?&gt;
&lt;config&gt;
      &lt;modules&gt;
            &lt;Spinonesolutions_Helloworld&gt;
                  &lt;version&gt;0.1.0&lt;/version&gt;
            &lt;/Spinonesolutions_Helloworld&gt;
      &lt;/modules&gt;
    &lt;frontend&gt;
        &lt;routers&gt;
            &lt;spinonesolutions&gt;      &lt;!-- I make this match my front name but I'm not sure it matters --&gt;
                &lt;use&gt;standard&lt;/use&gt; &lt;!-- Use standard routing as opposed to admin.  IE: frontend vs admin --&gt;
                &lt;args&gt;
                    &lt;module&gt;Spinonesolutions_Helloworld&lt;/module&gt;  &lt;!-- The module to search for controllers --&gt;
                    &lt;frontName&gt;spinonesolutions&lt;/frontName&gt; &lt;!-- The first descriminator in the path.  "spinonesolutions" in http://localhost/spinonesolutions/ --&gt;
                &lt;/args&gt;
            &lt;/spinonesolutions&gt;
        &lt;/routers&gt;
    &lt;/frontend&gt;
      &lt;global&gt;
            &lt;models&gt;
                  &lt;spinonesolutions_helloworld&gt; &lt;!-- This is used when istanting your Model EG: Mage::getModel("spinonesolutions_helloworld/hellworld") --&gt;
                        &lt;class&gt;Spinonesolutions_Helloworld_Model&lt;/class&gt;      &lt;!-- That class to use when isntanting objects of type above. --&gt;
                  &lt;/spinonesolutions_helloworld&gt;
            &lt;/models&gt;
      &lt;/global&gt;
&lt;/config&gt;</pre>
<p>Let’s start adding pieces onto our URL and explore what happens in Magento.  Adding one piece yields {base}/spinonesolutions/foo/.  This is asking Magento to invoke the <strong>indexAction()</strong> of the <strong>FooController</strong>, more specifically <strong>Spinonesolutions_Helloworld_FooController</strong>.</p>
<p>That Class doesn’t exist in our current code base so we need to create it.  Following Magento’s naming conventions and our choices in config.xml the filename and path for <strong>Spinonesolutions_Helloworld_FooController</strong> must be: <strong>/Spinonesolutions/Helloworld/controllers/FooController.php</strong>.</p>
<pre class="php" name="code">&lt;?php
class Spinonesolutions_Helloworld_FooController extends Mage_Core_Controller_Front_Action {
      //indexAction is the default Action for any controller
      function indexAction() {
            echo "Spinonesolutions_Helloworld_FooController.indexAction()";
      }    
}</pre>
<p>Now we’ll take it to the next level and add another piece to the URL yielding {base}/spinonesolutions/foo/bar/.  This is asking Magento to invoke the <strong>barAction()</strong> of the <strong>FooController</strong> (<strong>Spinonesolutions_Helloworld_FooController</strong>). Let’s add that action to our growing controller.</p>
<pre class="php" name="code">&lt;?php
class Spinonesolutions_Helloworld_FooController extends Mage_Core_Controller_Front_Action {
      //indexAction is the default Action for any controller
      function indexAction() {
            echo "Spinonesolutions_Helloworld_FooController.indexAction()";
      }

      //{base}/spinonesolutions/bar/
      function barAction() {
            echo "Spinonesolutions_Helloworld_FooController.barAction()";
      }
}</pre>
<p>That covers the basics for controllers.  Setup your route in the <strong>config.xml</strong> then follow the proper naming conventions when creating your classes and you should be all set.</p>
<p>Download the source &#8211; <a href="http://www.spinonesolutions.com/wp-content/uploads/2009/10/Helloworld_v2.rar">Helloworld_v2</a></p>
<ol>
<li><a title="Part I : Custom Module" href="http://www.spinonesolutions.com/2009/09/magento-custom-module-part-i/">Part I : Custom Module</a></li>
<li><a title="Part II : Models" href="http://www.spinonesolutions.com/2009/10/magento-part-ii-models/">Part II : Models</a></li>
<li><a title="Part III : Controllers" href="http://www.spinonesolutions.com/2009/10/magento-part-iii-controllers/">Part III : Controllers</a></li>
<li><a title="Part IV : Extending Models" href="http://www.spinonesolutions.com/2009/10/magento-part-iv-extending-models/">Part IV : Extending Models</a></li>
<li><a title="Part V: Data Layer" href="http://www.spinonesolutions.com/2009/10/magento-part-v-data-layer/">Part V : Data Layer</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.spinonesolutions.com/2009/10/magento-part-iii-controllers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
