Controller calling another controller
Posted: Tue Nov 06, 2012 5:59 pm
Is it possible for controller A to call another controller B, let B prepares the data, and pass control and data back to A?
OpenCart Community Forum - Discuss shopping cart and e-commerce solutions.
https://forum.opencart.com/
Great! Thanks sv2109.sv2109 wrote:Try method getChild($route, $args) from /system/engine/controller.php
Code: Select all
class ControllerModuleModule1 extends Controller {
protected function index() {
$result = $this->getChild('module/module2');
}
}
Qphoria wrote:Look at the catalog/controller/common/home.php file
You'll note that it has no real content. But it calls its children, which are modules... but modules are just mini-controllers that don't call the output dispatch directly, because the main controllers do it.
But you can pretty much load any module and place it. The module name is its exported variable name "latest" module is called by "$latest", etc
Code: Select all
ob_start();
$this->getChild('checkout/cart/add'); // for some reason we have echo here
$result = ob_get_clean();
// $result = NULL
Hey Man. Don't Take Me Wrong, But...I Love Yousv2109 wrote:Try method getChild($route, $args) from /system/engine/controller.php
Hi Q,Qphoria wrote:Look at the catalog/controller/common/home.php file
You'll note that it has no real content. But it calls its children, which are modules... but modules are just mini-controllers that don't call the output dispatch directly, because the main controllers do it.
But you can pretty much load any module and place it. The module name is its exported variable name "latest" module is called by "$latest", etc
Code: Select all
$this->load->controller( $route, $args );