Actions

September 14, 2009 at 10:51 am Leave a comment

Actions are classes that extend Mage_Core_Controller_Front_Action which, in turn, extends Mage_Core_Controller_Varien_Action. Actions also have a dispatch method, but this method dispatches the request to an action method. Action methods have the word “Action” appended to their names to distinguish them from normal class methods. Appending a word to the method name also helps to stop people from running unexpected methods from the URL. Imagine someone requesting example.com/index.php/customer/account/__destruct. If the system did not protect action names, the resulting method call would look something like this:

$controllerInstance->__destruct();
Something like this could potentially be a vector to open up attacks on your site.

But, I digress,Magento does protect the action method names by appending Action to any value taken from the URL, so this argument is purely academic.
During the dispatch event, the preDispatch method is called, and following the actual execution of the action method, the postDispatch method is called. By default, the postDispatch will save the current URL into the user’s session as the last URL visited.
Action and action methods arewhere the primary business logic for a request happens. Typically the action methods will load a model or two based on IDs or other URL parameters, kick off a few methods of these models, and then run the layout sequence. Having the action methods be responsible for outputting their own layout is an important issue to understand. This makes it more difficult to integrate with other systems, as you cannot as easily supplant your own layout or templating methods after executing the business logic. Also, it does not allow for any “post dispatch” logic to make any alterations to the output.

Advertisement

Entry filed under: Magento Basic. Tags: .

Routers Database Design

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Categories

Archives

Top Rated

Blog Stats

  • 5,814 hits

 

September 2009
M T W T F S S
     
 123456
78910111213
14151617181920
21222324252627
282930  

Follow

Get every new post delivered to your Inbox.