title: Opencart: How To Pass Data Variable From Parent To Child Controller
body: <p>Is there any simple solution to pass $this->data variable from parent controller to all children controllers.</p>
  
  <p>All what I try bring empty array to child.</p>
  
  <p>When I change the file "system/engine/controller.php" like below:</p>
  
  <pre><code>protected function getChild($child, $args = array()) {
      $action = new Action($child, $args);
  
      if (file_exists($action-&gt;getFile())) {
          require_once($action-&gt;getFile());
  
          $class = $action-&gt;getClass();
  
          $controller = new $class($this-&gt;registry);
  
          //$controller-&gt;{$action-&gt;getMethod()}($action-&gt;getArgs());
          $controller-&gt;{$action-&gt;getMethod()}($action-&gt;getArgs()+array('parent-data'=&gt;$this-&gt;data));
  
          return $controller-&gt;output;
      } else {
          trigger_error('Error: Could not load controller ' . $child . '!');
          exit();                 
      }       
  }
  </code></pre>
  
  <p>Then I try to read the variable 'parent-data' from the passed arguments in the child controller:</p>
  
  <pre><code>if (isset($setting['parent-data'])) {
      echo "&lt;pre&gt;".print_R($setting['parent-data'],true)."&lt;/pre&gt;";
  }
  </code></pre>
  
  <p>As a result I get an empty array:</p>
  
  <pre><code>Array
  (
      [modules] =&gt; Array
         (
          )
  )
  </code></pre>