Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should create a custom <strong>router</strong> that will be used additionally to the default router. To add a new router to the config, use this XML:</p> <pre><code>&lt;default&gt; &lt;web&gt; &lt;routers&gt; &lt;arbitrary_name&gt; &lt;area&gt;frontend&lt;/area&gt; &lt;class&gt;Your_Module_Controller_Router_Something&lt;/class&gt; &lt;/arbitrary_name&gt; &lt;/routers&gt; &lt;/web&gt; &lt;shorturls&gt; &lt;/shorturls&gt; &lt;/default&gt; </code></pre> <p><strong>The router could look like this:</strong></p> <pre><code>class Your_Module_Controller_Router_Something extends Mage_Core_Controller_Varien_Router_Abstract { private static $_module = 'your_module'; private static $_realModule = 'Your_Module'; private static $_controller = 'your_controller'; private static $_controllerClass = 'Your_Module_ControllerClassName'; private static $_action = 'your_action'; /** * @var Zend_Controller_Request_Http */ protected $_request; /** * Front controller looks for collectRoutes() although it is not defined * in abstract router class! * * (non-PHPdoc) * @see Mage_Core_Controller_Varien_Router_Standard::collectRoutes() */ public function collectRoutes() { // nothing to do here } /* (non-PHPdoc) * @see Mage_Core_Controller_Varien_Router_Abstract::match() */ public function match(Zend_Controller_Request_Http $request) { $this-&gt;_request = $request; // here you will have to implement your matching: // - detect if the request should be matched by this router // (i.e. check for "frontname" after base url) // - return false if not // - otherwise: $this-&gt;_setRequestRoute(); $this-&gt;_dispatch(); return true; } /** * @return void */ protected function _setRequestRoute() { $this-&gt;_request-&gt;setModuleName(self::$_module); $this-&gt;_request-&gt;setControllerName(self::$_controller); $this-&gt;_request-&gt;setActionName(self::$_action); $this-&gt;_request-&gt;setControllerModule(self::$_realModule); } /** * @return void */ protected function _dispatch() { $this-&gt;_request-&gt;setDispatched(true); $controller = Mage::getControllerInstance( self::$_controllerClass, $this-&gt;_request, $this-&gt;_response ); $controller-&gt;dispatch(self::$_action); } } </code></pre> <p>The important method is <code>match()</code> which will be called for every request and has to determine if the router is responsible for the request and if yes, dispatch it. This router would always dispatch the same controller action <code>your_controller/your_action</code>.</p> <p>You might also want to make some parameters available based on the URL: <code>$this-&gt;_request-&gt;setParam(key, value)</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload