B-and-P
B-and-P

Reputation: 1713

Opencart call function from module controller

I've tried asking this on Opencart forums (thread link), but still can't quite get it, though someone tried to explain this to me. I hope someone here can help.

I've written some extensions before where I have a custom function in the controller called from view , for example: if I edit admin/controller/sale/customer.php and after index() function add

public function foo(){
//code here
}

I can access it by using

index.php?route=sale/customer/foo

Now I have a module in catalog, could I access a function in it's controller from view, in the below example "foo"?

my_module.php:

class ControllerModuleMyModule extends Controller {
   protected function index($setting) {
...
}
public function foo(){
...
}

Basically, I want to make an AJAX call to it from whatever page/route the module is on. Many thanks in advance.

Upvotes: 3

Views: 6223

Answers (1)

Jay Gilford
Jay Gilford

Reputation: 15151

This can be done in the same way you would for any module. For instance, if you'd added foo() to /catalog/controller/module/cart.php you would use

index.php?route=module/cart/foo

There's nothing special about the module controllers compared with any other accessible module

Upvotes: 4

Related Questions