Magento overloading a controller
I know there are a lot of examples out there for this issue and i think i read all of them, at least I feel so, a little bit confused :-) I think first of all i need basic conzept respectively a better appreciation of how is the best way to change the whole customer frontend dashboard and extend it with additional methods. I stuck a litte bit with this, maybe this is the wrong way, maybe not, hopefully you can help me finding the right way.
All needed files are located i开发者_JAVA百科n:
app/code/local/Company/Customer/etc/config.xml
app/code/local/Company/Customer/controllers/AccountController.php
app/code/local/Company/Customer/controllers/IndexController.php
Atm I play with these path's:
domain.com/customer/
overwritten by:
<frontend>
<routers>
<customer>
<use>standard</use>
<args>
<module>Company_Customer</module>
<frontName>customer</frontName>
</args>
</customer>
</routers>
</frontend>
the above code is working, the overloading class is executed with the following function:
function indexAction();
and the path: domain.com/customer/ or domain.com/customer/index/ is functional.
So far, so good. But now I also need all the other path's and their functionality, e.g. the domain.com/customer/account/ path, normally executed and routed to the following path:
app/code/core/Mage/Customer/controllers/AccountController.php
and here's the crux, is it possible to load the AccountController by execute or load them in the
IndexController.php class with a new method e.g. function accountAction();
and stop Magento routing
to the above core path? Or is it better to do this the way I did by rewrite the magento router to my own module, to:
app/code/local/Company/Customer/controllers/AccountController.php
Maybe there are some other ways but my router isn't working:
<frontend>
<routers>
<customer_account>
<use>standard</use>
<args>
<module>Company_Customer_Account</module>
<frontName>customer_account</frontName>
</args>
</customer_account>
</routers>
</frontend>
EDIT:
This is the from the error.log:
2011-07-25T10:36:46+00:00 ERR (3): Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'Mage/Customer/AccountController.php' for inclusion (include_path='/html/magento/app/code/local:/html/magento/app/code/community:/html/magento/app/code/core:/html/magento/lib:.:/usr/local/php/lib/php:/usr/local/php/lib/php/PEAR') in /html/magento/lib/Varien/Autoload.php on line 93
I think this means that the router works but the file isn't found, right?!
Any suggestions would be great. Thanks!
--------------------------------------------
----------------UPDATE----------------
--------------------------------------------
Thanks for your reply. I allready tried the alternative rewrite in the global section before:
<rewrite>
<Company_Customer_Account>
<from><![CDATA[#^/customer/account/#]]></from>
<to>/customer/account/</to>
</Company_Customer_Account>
</rewrite>
and with your code:
<rewrite>
<Company_Customer_Account>
<from>/customer/account/index/</from>
<to>/customer/account/index/</to>
</Company_Customer_Account>
</rewrite>
both don't work, what i'm missing?
Here's the AccountController.php
<?php
//require_once 'Mage/Customer/controllers/AccountController.php';
class Extension_Modul_AccountController extends Mage_Customer_AccountController {
# Overloaded indexAction
public function indexAction()
{
echo "executed";
parent::indexAction();
}
}
Your front name : 'customer_account' needs to be as before 'customer' in the second example.
When you do domain.com/customer/ it automatically refers to IndexController -> indexAction();
In order to get domain.com/customer/account it can be done similarly and account here refers not to accountAction but AccountController.
The path system is usually like : Module/SomeController/someAction.
Alternatively you could add in your config global tag, sth like:
<rewrite><module_control_action><from>/module/control/action/</from><to>/mymodule/somecontrol/someaction/</to></module_control_action></rewrite>
精彩评论