Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

[ SOLVED ] How do I create a new controller/action/view on an existing module? 
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

This was how I went about it, but I get the 404 Not Found page.

1. Create my controller as follows:

-- Review
 
-- controllers
  
-- Ajax
   
-- ProductController.php

It contains the following:

class Mage_Review_Ajax_ProductController extends Mage_Core_Controller_Front_Action
{
    
public function viewAction()
    
{
        $this
->loadLayout(false);
        
$this->renderLayout();
    
}
}

2. Create a review view block in layout/review.xml as follows:

<review_ajax_product_view>
    <
block type="review/customer_view" name="customer_ajax_review" output="toHtml" template="review/ajax/product/view.phtml" />
</
review_ajax_product_view>

3. Create my template in review/ajax/product/view.phtml.

4. Refresh all cache and go to http://www.mydomain.com/review/ajax/product/view.

I get a 404. I must be missing something about how this works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
HAL10001
Member
 
Avatar
Total Posts:  52
Joined:  2008-06-02
Ann Arbor, MI
 

I had the wrong URL. It should be:

http://www.mydomain.com/review/ajax_product/view

Apparently when you have a folder within the controllers folder it does not add it as a folder, but appends it with an underscore to the action. So it works now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
quanza
Sr. Member
 
Avatar
Total Posts:  97
Joined:  2008-12-02
Tokyo, Japan
 

Just wanted to say, thank you *very* much for posting this.

A note to devs who decide to create a new local module rather than extend one that already exists (since future upgrading may not be as easy), the

output="toHtml"
parameter is *super* important.  The call to loadLayout(false) turns off loading page-layout info, so w/o the toHtml parameter you’ll just get a blank page.  I just lost a few hours missing this important step.

now to lose a few more hours with other Magento shenanigans ... :/

 
Magento Community Magento Community
Magento Community
Magento Community
 
hcpunk
Jr. Member
 
Total Posts:  24
Joined:  2009-04-06
 

I tried following these directions but I just always end up with the 404 page. I’ve tried several other approaches without any success. So frustrating.

 
Magento Community Magento Community
Magento Community
Magento Community
 
woot woot
Jr. Member
 
Total Posts:  5
Joined:  2010-10-12
 

I got the same problem 404, any hint since last time?
Thank you.

Edit: hint is to work in core/mage if the file doesn’t exist yet (and not in local/mage).

 
Magento Community Magento Community
Magento Community
Magento Community
 
Admin_Fasha
Jr. Member
 
Total Posts:  3
Joined:  2011-03-24
 

Thanks for help

 
Magento Community Magento Community
Magento Community
Magento Community
 
hippoglollum
Sr. Member
 
Total Posts:  97
Joined:  2010-04-07
 

I know it\’s an old post and that is solved but i don’t know why this doesn’t work form me.

I would modify the xmlconnect module to get work the url
http://www.mydomain.com/xmlconnect/catalog/stock
so I did the following:

- Added the action method in CatalogController.php in XmlConnect/controllers/

public function stockAction()
    
{    
    Mage
::log('stockAction');
        try 
{
            $this
->loadLayout(false);
            
$this->renderLayout();
        
catch (Mage_Core_Exception $e{
            $this
->_message($e->getMessage(), self::MESSAGE_STATUS_ERROR);
        
catch (Exception $e{
            $this
->_message($this->__('Unable to load search.'), self::MESSAGE_STATUS_ERROR);
            
Mage::logException($e);
        
}
    }

- Added a new class file app/code/core/Mage/XmlConnect/Block/Catalog/Stock.php

class Mage_XmlConnect_Block_Catalog_Stock extends Mage_XmlConnect_Block_Catalog
{
    
    
protected function _toHtml()
    
{
        Mage
::log('stock_toHtml');
        echo 
"hello";
        
        return 
"test";
    
}
}

- Added a new block in xmlconnect.xml layout file (in the “base” theme directory)

<xmlconnect_catalog_stock>
        <
block type="xmlconnect/catalog_stock" name="xmlconnect.catalog.stock" output="toHtml" />
    </
xmlconnect_catalog_stock>

I don’t see no log and i get only a 404 error page.

Can someone help me?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jase007
Guru
 
Total Posts:  388
Joined:  2013-11-05
 

Hello,

Have a look this thread for this http://blog.baobaz.com/en/blog/magento-module-create-your-own-controller

Hope this will help you!!

Thanks

iLoveMage

 
Magento Community Magento Community
Magento Community
Magento Community
 
hippoglollum
Sr. Member
 
Total Posts:  97
Joined:  2010-04-07
 

thank you Jase007 but it still doesn’t work.

In this post I ask how to add a new action.

I presume that adding a new action method into the controller and printing a string it will work but it doensn’t.

Your link supports my idea but it doensn’t work.

I will try to build a new module so that the XmlConnect module structure does not influence the controller

All other suggestions will be appreciated.

Thank you all.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top