Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The above code works to a point and requires a bit more understanding and explanation. Here is what I came up with after tooling around with this for the last 10 hours or so:</p> <p>File:config.xml</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; &lt;modules&gt; &lt;AJW_Bestselling&gt; &lt;version&gt;1.6.0.0.1&lt;/version&gt; &lt;/AJW_Bestselling&gt; &lt;/modules&gt; &lt;frontend&gt; &lt;routers&gt; &lt;bestselling&gt; &lt;use&gt;standard&lt;/use&gt; &lt;args&gt; &lt;module&gt;AJW_Bestselling&lt;/module&gt; &lt;frontName&gt;bestsellers&lt;/frontName&gt; &lt;/args&gt; &lt;/bestselling&gt; &lt;/routers&gt; &lt;layout&gt; &lt;updates&gt; &lt;bestselling&gt; &lt;file&gt;bestselling.xml&lt;/file&gt; &lt;/bestselling&gt; &lt;/updates&gt; &lt;/layout&gt; &lt;/frontend&gt; &lt;global&gt; &lt;events&gt; &lt;controller_front_init_routers&gt; &lt;observers&gt; &lt;bestselling&gt; &lt;class&gt;AJW_Bestselling_Controller_Router&lt;/class&gt; &lt;method&gt;initControllerRouters&lt;/method&gt; &lt;/bestselling&gt; &lt;/observers&gt; &lt;/controller_front_init_routers&gt; &lt;/events&gt; &lt;models&gt; &lt;bestselling&gt; &lt;class&gt;AJW_Bestselling_Model&lt;/class&gt; &lt;/bestselling&gt; &lt;/models&gt; &lt;blocks&gt; &lt;bestselling&gt; &lt;class&gt;AJW_Bestselling_Block&lt;/class&gt; &lt;/bestselling&gt; &lt;/blocks&gt; &lt;helpers&gt; &lt;bestselling&gt; &lt;class&gt;AJW_Bestselling_Helper&lt;/class&gt; &lt;/bestselling&gt; &lt;/helpers&gt; &lt;/global&gt; </code></pre> <p></p> <p>File:Controller/Router.php</p> <pre><code>&lt;?php class AJW_Bestselling_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract { private static $_module = 'bestsellers'; private static $_realModule = 'AJW_Bestselling'; private static $_controller = 'index'; private static $_controllerClass = 'AJW_Bestselling_Controller_Index'; private static $_action = 'view'; public function initControllerRouters($observer) { $front = $observer-&gt;getEvent()-&gt;getFront(); $front-&gt;addRouter('bestselling', $this); } public function match(Zend_Controller_Request_Http $request) { $this-&gt;_request = $request; $identifier = trim($request-&gt;getPathInfo(), '/'); //If Magento Is Not Installed Reroute To Installer if (!Mage::isInstalled()) { Mage::app()-&gt;getFrontController()-&gt;getResponse() -&gt;setRedirect(Mage::getUrl('install')) -&gt;sendResponse(); exit; } //If we dont match our router then let another router take over if(!substr($identifier,0,strlen('bestsellers')) == 'bestsellers'){ return false; } //If we do match the our router then lets add some data and dispatch our controller else{ $route_params = str_replace ( "bestsellers/" , "" , $identifier ); $rewrite = Mage::getModel('core/url_rewrite'); $rewrite-&gt;setStoreId(1); $rewrite-&gt;loadByRequestPath($route_params); $category_route = $rewrite-&gt;getIdPath(); //Check to see if the route exists before we do anything else if(!$category_route != ""){ return false; }//Otherwise send the parameters to the request else{ $id = str_replace ( "category/" , "" , $category_route ); $this-&gt;_request-&gt;setParam('id',$id); } } $this-&gt;_setRequestRoute(); return true; } protected function _setRequestRoute() { $this-&gt;_request-&gt;setModuleName(self::$_module) -&gt;setControllerName(self::$_controller) -&gt;setActionName(self::$_action) -&gt;setControllerModule(self::$_realModule); return true; } } </code></pre> <p>File:controllers/IndexController.php <pre><code>class AJW_Bestselling_IndexController extends Mage_Core_Controller_Front_Action{ public function indexAction(){ echo "This is the index controller"; die(); } public function viewAction(){ $this-&gt;loadLayout(); $this-&gt;renderLayout(); } } </code></pre> <p>What happens is if you go to just mysite.com/bestsellers/ The router will load the index controller. However if you go to bestsellers/some/category/url.html it will fire the viewAction and the category id will be sent to be used by the controller.</p> <p>The concept behind this is the ability to display content to each of your categories based on the first portion of the url after the .com - Some ideas might be best selling, most recommended, top reviewed, category questions .. anything that would form a many to one( or many) relationship with a particular category.</p> <p>Also note that you could potentially use this same module to act as a router for multiple modules by conditionally setting the params of the AJW_Bestselling_Controller_Router.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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