Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento Custom Router Lost Layout Object
    primarykey
    data
    text
    <p>It seems like everything is being properly configured and I can get the output that I want but I would prefer not echoing the layout object directly from my controller:</p> <p>Here is what Im working with config.xml</p> <pre><code>&lt;config&gt; &lt;modules&gt; &lt;ALS_Bestselling&gt; &lt;version&gt;0.1.0&lt;/version&gt; &lt;/ALS_Bestselling&gt; &lt;/modules&gt; &lt;global&gt; &lt;models&gt; &lt;bestselling&gt; &lt;class&gt;ALS_Bestselling_Model&lt;/class&gt; &lt;/bestselling&gt; &lt;/models&gt; &lt;blocks&gt; &lt;bestselling&gt; &lt;class&gt;ALS_Bestselling_Block&lt;/class&gt; &lt;/bestselling&gt; &lt;/blocks&gt; &lt;helpers&gt; &lt;bestselling&gt; &lt;class&gt;ALS_Bestselling_Helper&lt;/class&gt; &lt;/bestselling&gt; &lt;/helpers&gt; &lt;/global&gt; &lt;frontend&gt; &lt;layout&gt; &lt;updates&gt; &lt;als_bestselling&gt; &lt;file&gt;bestselling.xml&lt;/file&gt; &lt;/als_bestselling&gt; &lt;/updates&gt; &lt;/layout&gt; &lt;/frontend&gt; &lt;default&gt; &lt;web&gt; &lt;routers&gt; &lt;bestselling_router&gt; &lt;area&gt;frontend&lt;/area&gt; &lt;class&gt;ALS_Bestselling_Controller_Router&lt;/class&gt; &lt;/bestselling_router&gt; &lt;/routers&gt; &lt;/web&gt; &lt;shorturls&gt; &lt;/shorturls&gt; &lt;/default&gt; &lt;/config&gt; </code></pre> <p>and</p> <pre><code>#File: Controller/Router.php &lt;?php class ALS_Bestselling_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract { private static $_module = 'bestsellers'; private static $_realModule = 'ALS_Bestselling'; private static $_controller = 'index'; private static $_controllerClass = 'ALS_Bestselling_Controller_Index'; private static $_action = 'view'; public function initControllerRouters($observer) { $front = $observer-&gt;getEvent()-&gt;getFront(); $front-&gt;addRouter('bestselling', $this); } public function collectRoutes() { // nothing to do here } public function match(Zend_Controller_Request_Http $request) { $this-&gt;_request = $request; $front = $this-&gt;getFront(); $identifier = trim($request-&gt;getPathInfo(), '/'); if(!substr($identifier,0,strlen('bestsellers')) == 'bestsellers'){ return false; }else{ //$rewrite = Mage::getModel('core/url_rewrite'); $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(); //If no route exists for category send to a different router 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(); $this-&gt;_dispatch(); return true; } } 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); } 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>and</p> <pre><code>File: Controller/Index.php class ALS_Bestselling_Controller_Index extends Mage_Core_Controller_Front_Action{ public function viewAction(){ $layout = Mage::app()-&gt;getLayout(); $layout-&gt;generateXml()-&gt;generateBlocks(); $render = $layout-&gt;getBlock('root')-&gt;toHtml(); echo $render; } } </code></pre> <p>The previous works but the following:</p> <pre><code>$update = $this-&gt;getLayout()-&gt;getUpdate(); $update-&gt;addHandle('default'); $this-&gt;renderLayout(); </code></pre> <p>throws an error Call to a member function appendBody() on a non-object.</p> <p>Is this how I am suppose to do this or is there something missing from the recipe?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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