I need to override a controller (../Mage/Customer/controllers/AccountController.php) in order to enable user to upload a photo from "Account Information" form. I've manually created "photo" file upload field and added "enctype=multipart/form-data" to form .phtml file.
Now I need to handle submisison so that the actual file is saved on the server and path is saved into my database.
When I put Varien_File_Uploader code into original AccountController.php the file is saved on the server. I don't want to modify core files so I've created my own module with "etc/config.xml" and "controllers/AccountController.php".
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Abcdef_Photoupload>
<version>0.1.0</version>
</Abcdef_Photoupload>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<Abcdef_Photoupload before="Mage_Customer_AccountController">
Abcdef_Photoupload_Frontend_Customer
</Abcdef_Photoupload>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
for now, in my controllers/AccountController.php I've put
<?php
echo "test";
exit;
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
class Abcdef_Photoupload_Frontend_Customer_AccountController extends Mage_Customer_AccountController
{[my code]}
neither "echo", nor [my code] get executed. Module is enabled and visible in back-end. How do I get my customized controller to work?
-
you need put exit function on a functionAmit Bera– Amit Bera ♦2014年09月08日 08:12:25 +00:00Commented Sep 8, 2014 at 8:12
-
Please take your time to accept an answer if it helped you so that the question does not count as unanswered anymoreFabian Schmengler– Fabian Schmengler2015年12月18日 14:37:09 +00:00Commented Dec 18, 2015 at 14:37
4 Answers 4
Please try replacing following code in your config.xml
<routers>
<customer>
<use>standard</use>
<args>
<modules>
<Abcdef_Photoupload before="Mage_Customer">
Abcdef_Photoupload
</Abcdef_Photoupload>
</modules>
</args>
</customer>
</routers>
and in the /controllers/AccountController.php file change the class name from
class Abcdef_Photoupload_Frontend_Customer_AccountController extends Mage_Customer_AccountController
To
class Abcdef_Photoupload_AccountController extends Mage_Customer_AccountController
both following extension could also help for customer profile image: http://www.magentocommerce.com/magento-connect/upload-profile-image.html http://www.magentocommerce.com/magento-connect/avatar.html
-
-
Please clear the cache and then check and have you added exit in the function not on the file as commented by Amit. can you please specify the magento version.Namita sheth– Namita sheth2014年09月09日 04:37:07 +00:00Commented Sep 9, 2014 at 4:37
-
Hi Namita. I've cleared the cache and added exit in the function and outside of it, no success. The magento version is 1.8.1.Alan– Alan2014年09月09日 05:38:27 +00:00Commented Sep 9, 2014 at 5:38
-
please check for any spell mistake at with folder name or in file. OR any installed extension override same controller file, Because the above code did work for me on same magento version 1.8.1.0Namita sheth– Namita sheth2014年09月09日 07:19:41 +00:00Commented Sep 9, 2014 at 7:19
-
1If you want to add the profile image for the customer you can also try following free extension. linkNamita sheth– Namita sheth2014年09月09日 07:30:12 +00:00Commented Sep 9, 2014 at 7:30
<modules>
<Abcdef_Photoupload before="Mage_Customer_AccountController">
Abcdef_Photoupload_Frontend_Customer
</Abcdef_Photoupload>
</modules>
Should be:
<module>
<Abcdef_Photoupload before="Mage_Customer_AccountController">
Abcdef_Photoupload_Frontend_Customer
</Abcdef_Photoupload>
</module>
-
Unfortulatly this doesn't help.Alan– Alan2014年09月08日 09:03:39 +00:00Commented Sep 8, 2014 at 9:03
Check you create this folder structure:
app/code/local/Abcdef/Photoupload/controllers/Frontend/Customer/AccountController.php
Please Refer this link to override Customer Account controller .
http://inchoo.net/dev-talk/how-to-extend-magento-core-controller/
The correct configuration is:
<routers>
<customer>
<use>standard</use>
<args>
<modules>
<Abcdef_Photoupload before="Mage_Customer">Abcdef_Photoupload_Frontend_Customer</Abcdef_Photoupload>
</modules>
</args>
</customer>
</routers>
Note that it's before=Mage_Customer, not before=Mage_Customer_AccountController. You don't override single controllers, but define - by class prefix - which controllers may handle a module, i.e. Mage_Customer, and in which order the actions are looked up (that's why you need the "before" definition, if you override existing actions in Mage_Customer_AccountController).