2
votes

how can I from template trigger specific function in controller. Lets say I have a search module and after user click on button search I would like to perform some actions (if any is wrong, please get me noted).

  1. Handle the form (which I've learned I can do throw Tools::getValue('name_of_variable'))

  2. The form I need to evaluate and do DB search. Where should I put my code if not in the custom function. But how to asure that this exactly function will be trigerred. In custom php file it is easy, because there is no other code then the main code, which is repeatly called everytime I call that file. But here I want to call just the exact one function.

Or which files I need to include to use DB and smarty interface and I can do this throw raw PHP code.

Please help me, because I've been stuck at this about two weeks.

Thanks

1

1 Answers

0
votes

There is a specific hook for the search, called "actionSearch".

  • Create a module
  • in the install() method, call $this->registerHook('actionSearch');
  • in the function hookActionSearch(), implement your code
  • If you want to assign something to smarty, use the global scope with Context::getContext()->smarty->assign()
  • if you want to use these variables in Smarty, then it depends where you want to display things...

For example, the module StatsSearch implements this hook.