Post by charlesso » 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?

New member

Posts

Joined
Mon Sep 20, 2010 11:33 am

Post by sv2109 » Tue Nov 06, 2012 9:11 pm

Try method getChild($route, $args) from /system/engine/controller.php

My php is more better than my english.

You can find my Extensions here.


User avatar
Newbie

Posts

Joined
Sun Nov 04, 2012 6:10 am
Location - Ukraine

Post by charlesso » Tue Nov 06, 2012 9:18 pm

sv2109 wrote:Try method getChild($route, $args) from /system/engine/controller.php
Great! Thanks sv2109.

Ummm. Now i need to search for documentation n maybe sample code....

New member

Posts

Joined
Mon Sep 20, 2010 11:33 am

Post by sv2109 » Wed Nov 07, 2012 2:30 am

Try this:

Code: Select all

class ControllerModuleModule1 extends Controller {
  protected function index() {
    $result = $this->getChild('module/module2');
  }
}

My php is more better than my english.

You can find my Extensions here.


User avatar
Newbie

Posts

Joined
Sun Nov 04, 2012 6:10 am
Location - Ukraine

Post by Qphoria » Wed Nov 07, 2012 10:41 am

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

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by charlesso » Wed Nov 07, 2012 3:14 pm

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

Thanks Q.

New member

Posts

Joined
Mon Sep 20, 2010 11:33 am

Post by commanddotcom » Thu Jun 27, 2013 4:51 am

sv2109, came up with a nice solution.

But can anyone explane why ob_start() ignores?

Code: Select all

ob_start();
   $this->getChild('checkout/cart/add'); // for some reason we have echo here
$result = ob_get_clean(); 
// $result = NULL	

User avatar
New member

Posts

Joined
Tue Aug 14, 2012 8:41 pm

Post by aldoanizio » Sat Jun 29, 2013 2:01 am

sv2109 wrote:Try method getChild($route, $args) from /system/engine/controller.php
Hey Man. Don't Take Me Wrong, But...I Love You :laugh:

Saved my life. Thanks for the Tip.

Newbie

Posts

Joined
Tue Feb 26, 2013 7:47 pm

Post by charlesso » Fri May 29, 2015 8:49 am

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
Hi Q,

This getChild() method can call a child.

But how do I call the Child's methods and pass variables to the methods from the calling controller?

New member

Posts

Joined
Mon Sep 20, 2010 11:33 am

Post by JNeuhoff » Sun May 31, 2015 2:30 am

In OpenCart 2.0.x versions, this is quite simple:

Code: Select all

$this->load->controller( $route, $args );
This will execute the action specified by the route, with the optional given args, and returns the rendered output.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am

Who is online

Users browsing this forum: No registered users and 11 guests