Repy Posted October 30, 2011 Share Posted October 30, 2011 Hello there. I'm learning how overrides works, and I made my first one, but I'm not sure if its correct... could you check it please? The code is: class PasswordController extends PasswordControllerCore { public function process() { if (true) //check captcha here $this->errors[] = Tools::displayError('The captcha was wrong.'); else parent::process(); } } in the file /override/controllers/PasswordController.php. Also, is there a way to make it "installable" using the back end (like a module)? Thank you. Link to comment Share on other sites More sharing options...
Repy Posted October 31, 2011 Author Share Posted October 31, 2011 Anyone? Link to comment Share on other sites More sharing options...
Repy Posted November 3, 2011 Author Share Posted November 3, 2011 Owch... are you serious? In fact, I think the thing should be a little different, more or less like this: class PasswordController extends PasswordControllerCore { public function process() { if (Tools::isSubmit('email')) { if (!$mycaptchalib->check($_POST['captcha_field'])) $this->errors[] = Tools::displayError('Captcha was wrong.'); else parent::process(); } } } I'm not sure if i'm doing this right though. I fear it's not a safe way to extend the functionality. I know a little of french, should I ask things like this in the french forums? Link to comment Share on other sites More sharing options...
mexique1 Posted November 4, 2011 Share Posted November 4, 2011 Hi, Sorry, but I don't understand what you want... Does your code work ? Have you tested it ? If it works like you expect it to work, then what do you want ? Our agreement ? I don't know anything about the PasswordController, but yes, it seems correct. In most cases, the best thing to do when you need to override some PS class, is to check carefully the parent code, and extend it accordingly. And it seems this is what you did. AFAIK there's no API to "install" the override, at least you can make it user friendly by automatizing the copy of the file. But take care, the target could have already an override... Link to comment Share on other sites More sharing options...
Repy Posted November 7, 2011 Author Share Posted November 7, 2011 Thanks for your answer. Yep. It works perfectly. I just wanted a second opinion, because the override feature isn't very well documented (at least in english) so i wasn't sure i was doing it right And yes, I checked the 'parent' code to make sure the override makes sense. I see your point. Everything should work as long as there's no other override for the same controller. I don't know about multiple overrides... I think you can't do that unless you manually put them in the same file, because the override is dependent on the file name, and conflicts are likely, so one should solve this manually also. Thank you . Link to comment Share on other sites More sharing options...
mexique1 Posted November 7, 2011 Share Posted November 7, 2011 I think you can't do that unless you manually put them in the same file You can't do that, PHP will tell you that you cannot redeclare the class I mean, if you want to automate the override installation, don't forget to check if a file already exists ! Then, show a warning to the user, and ask him if he wants to replace his override with yours. In any case, overrides are designed to allow altering Prestashop's "core" without touching the core files themselves. If a user has an override, it's likely you wont't be able to replace it with yours, because the user has already customized PrestaShop. Complicated... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now