Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

Is it possible to hook functions in controller?

Started by yonghan, June 26, 2014, 07:13:03 AM

Previous topic - Next topic

yonghan

Hi,i would like to ask if it's possible to hook functions in controller?i.e i would like to extend add function in customer manage address controller to use other styles.insted of directly edit the controller or using javascript.thanks a lot.

abantecart

You can hook to any controller in the beginning and at the end. You can also have pre and post controllers

Check this manual:
http://www.abantecart.com/document_wiki/index.php/AbanteCart_Extension's_Developer_Guide#Hooks

abolabo

Quote from: yonghan on June 26, 2014, 07:13:03 AM
Hi,i would like to ask if it's possible to hook functions in controller?i.e i would like to extend add function in customer manage address controller to use other styles.insted of directly edit the controller or using javascript.thanks a lot.

of cource.

read this first
http://www.abantecart.com/document_wiki/index.php/AbanteCart_Extension%E2%80%99s_Developer_Guide#Hooks
and also you can open some extension's file with hooks for ex. default_pp_pro/core/default_pp_pro.php to look...
Also we have developer tools to generate extension https://github.com/abantecart/developer_tools_extension
You can build your own extension very fast.

yonghan

Thanks a lot for the replies,i'll take a look at the pre and post controller example from existing extensions.

yonghan

Hi abolabo,my question is not clear enough.What i would like to do is hook function i.e insert function in storefront/controller/pages/account/address.Is it possible to do that?Thanks

abolabo

every method of core-controller contain 2 hook calls:
//init controller data
$this->extensions->hk_InitData($this, __FUNCTION__);

and
//update controller data
$this->extensions->hk_UpdateData($this, __FUNCTION__);

You just should to add methods
public function onControllerPagesAccountAddress_InitData(){
    //write your code here
}

and

public function onControllerPagesAccountAddress_UpdateData(){
    //write your code here
}


yonghan

I've tried using Update_Data() to hook before,but when i run the code,the rest of the core function didn't work.

abolabo

Quote from: yonghan on July 26, 2014, 10:09:10 AM
I've tried using Update_Data() to hook before,but when i run the code,the rest of the core function didn't work.

i guess you call hook on all methods on core-controller.
use condition if($this->baseObject_method='name of method')  to define place when your hook must work

yonghan


Forum Rules Code of conduct
AbanteCart.com 2010 -