title: Custom open cart module install - Fatal error: Call to a member function get() on a non-object
body: <p>I am trying to write a custom module that will hook into <code>post.order.history.add</code> event and do a custom action. This is my module structure &amp; code so far:</p>
  
  <p><strong>admin\controller\module\mysite.php</strong></p>
  
  <pre><code>&lt;?php
  
  class ControllerModuleMysite extends Controller
  {
      private $error;
      private $logger;
  
      public function __construct()
      {
          $this-&gt;error  = array();
          $this-&gt;logger = new Log('MySite.log');
      }
  
      /* Event Hooks */
  
      public function install()
      {
          $this-&gt;load-&gt;model('extension/event');
  
          $this-&gt;model_extension_event-&gt;addEvent('mysite_NewOrder', 'post.order.history.add', 'module/mysite/on_order_history_add');
      }
  
      public function uninstall()
      {
          $this-&gt;load-&gt;model('extension/event');
  
          $this-&gt;model_extension_event-&gt;deleteEvent('mysite_NewOrder');
      }
  
      /* Admin Config Handler */
  
      public function index()
      {
          // Loading the language file of mysite
          $this-&gt;load-&gt;language('module/mysite');
  
          // Set the title of the page to the heading title in the Language file
          $this-&gt;document-&gt;setTitle($this-&gt;language-&gt;get('heading_title'));
  
          // Load the Setting Model  (All of the OpenCart Module &amp; General Settings are saved using this Model )
          $this-&gt;load-&gt;model('setting/setting');
  
          // Start If: Validates and check if data is coming by save (POST) method
          if (($this-&gt;request-&gt;server['REQUEST_METHOD'] == 'POST') &amp;&amp; $this-&gt;validate())
          {
              // Parse all the coming data to Setting Model to save it in database.
              $this-&gt;model_setting_setting-&gt;editSetting('mysite', $this-&gt;request-&gt;post);
  
              // To display the success text on data save
              $this-&gt;session-&gt;data['success'] = $this-&gt;language-&gt;get('text_success');
  
              // Redirect to the Module Listing
              $this-&gt;response-&gt;redirect($this-&gt;url-&gt;link('extension/module', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'));
          }
  
          // Assign the language data for parsing it to view
          $data['heading_title'] = $this-&gt;language-&gt;get('heading_title');
  
          $data['text_edit']           = $this-&gt;language-&gt;get('text_edit');
          $data['text_enabled']        = $this-&gt;language-&gt;get('text_enabled');
          $data['text_disabled']       = $this-&gt;language-&gt;get('text_disabled');
          $data['text_content_top']    = $this-&gt;language-&gt;get('text_content_top');
          $data['text_content_bottom'] = $this-&gt;language-&gt;get('text_content_bottom');
          $data['text_column_left']    = $this-&gt;language-&gt;get('text_column_left');
          $data['text_column_right']   = $this-&gt;language-&gt;get('text_column_right');
  
          $data['entry_code']       = $this-&gt;language-&gt;get('entry_code');
          $data['entry_layout']     = $this-&gt;language-&gt;get('entry_layout');
          $data['entry_position']   = $this-&gt;language-&gt;get('entry_position');
          $data['entry_status']     = $this-&gt;language-&gt;get('entry_status');
          $data['entry_sort_order'] = $this-&gt;language-&gt;get('entry_sort_order');
  
          $data['button_save']       = $this-&gt;language-&gt;get('button_save');
          $data['button_cancel']     = $this-&gt;language-&gt;get('button_cancel');
          $data['button_add_module'] = $this-&gt;language-&gt;get('button_add_module');
          $data['button_remove']     = $this-&gt;language-&gt;get('button_remove');
  
          // This Block returns the warning if any
          if (isset($this-&gt;error['warning'])) {
              $data['error_warning'] = $this-&gt;error['warning'];
          } else {
              $data['error_warning'] = '';
          }
  
          // This Block returns the error code if any
          if (isset($this-&gt;error['code'])) {
              $data['error_code'] = $this-&gt;error['code'];
          } else {
              $data['error_code'] = '';
          }
  
          // Making of Breadcrumbs to be displayed on site
          $data['breadcrumbs']   = array();
          $data['breadcrumbs'][] = array(
              'text' =&gt; $this-&gt;language-&gt;get('text_home'),
              'href' =&gt; $this-&gt;url-&gt;link('common/home', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'),
              'separator' =&gt; false
          );
          $data['breadcrumbs'][] = array(
              'text' =&gt; $this-&gt;language-&gt;get('text_module'),
              'href' =&gt; $this-&gt;url-&gt;link('extension/module', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'),
              'separator' =&gt; ' :: '
          );
          $data['breadcrumbs'][] = array(
              'text' =&gt; $this-&gt;language-&gt;get('heading_title'),
              'href' =&gt; $this-&gt;url-&gt;link('module/mysite', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL'),
              'separator' =&gt; ' :: '
          );
  
          $data['action'] = $this-&gt;url-&gt;link('module/mysite', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL');
  
          $data['cancel'] = $this-&gt;url-&gt;link('extension/module', 'token=' . $this-&gt;session-&gt;data['token'], 'SSL');
  
          // This block parses the status (enabled / disabled)
          if (isset($this-&gt;request-&gt;post['mysite_status'])) {
              $data['mysite_status'] = $this-&gt;request-&gt;post['mysite_status'];
          } else {
              $data['mysite_status'] = $this-&gt;config-&gt;get('mysite_status');
          }
  
          $data['header']      = $this-&gt;load-&gt;controller('common/header');
          $data['column_left'] = $this-&gt;load-&gt;controller('common/column_left');
          $data['footer']      = $this-&gt;load-&gt;controller('common/footer');
  
          $this-&gt;response-&gt;setOutput($this-&gt;load-&gt;view('module/mysite.tpl', $data));
  
      }
  
      protected function validate()
      {
          // Block to check the user permission to manipulate the module
          if (!$this-&gt;user-&gt;hasPermission('modify', 'module/mysite')) {
              $this-&gt;error['warning'] = $this-&gt;language-&gt;get('error_permission');
          }
  
          // Block returns true if no error is found, else false if any error detected
          if (!$this-&gt;error) {
              return true;
          } else {
              return false;
          }
      }
  
      /* Event Handlers */
  
      public function on_order_history_add($order_id)
      {
          // Load order data
          $this-&gt;load-&gt;model('checkout/order');
          $orderData = $this-&gt;model_checkout_order-&gt;getOrder($order_id);
  
          // Debug
          $this-&gt;logger-&gt;write(print_r($orderData, true));
  
          // TODO: call third-party api &amp; create hosting package
          // TODO: send success/error email notification to customer
      }
  }
  </code></pre>
  
  <p><strong>admin\language\english\module\mysite.php</strong></p>
  
  <pre><code>&lt;?php
  
  // Heading
  $_['heading_title']       = 'My Site';
  
  // Text
  $_['text_module']         = 'Modules';
  $_['text_edit']           = 'Edit My Site Module';
  $_['text_success']        = 'Success: You have modified module My Site!';
  
  // Entry
  $_['entry_status']        = 'Status:';
  
  // Error
  $_['error_permission']    = 'Warning: You do not have permission to modify module My Site!';
  $_['error_code']          = 'Code Required';
  </code></pre>
  
  <p><strong>admin\view\template\module\mysite.tpl</strong></p>
  
  <pre><code>&lt;?php echo $header; ?&gt;&lt;?php echo $column_left; ?&gt;
  
  &lt;div id="content"&gt;
    &lt;div class="page-header"&gt;
      &lt;div class="container-fluid"&gt;
        &lt;div class="pull-right"&gt;
          &lt;button type="submit" form="form-helloworld" data-toggle="tooltip" title="&lt;?php echo $button_save; ?&gt;" class="btn btn-primary"&gt;&lt;i class="fa fa-save"&gt;&lt;/i&gt;&lt;/button&gt;
          &lt;a href="&lt;?php echo $cancel; ?&gt;" data-toggle="tooltip" title="&lt;?php echo $button_cancel; ?&gt;" class="btn btn-default"&gt;&lt;i class="fa fa-reply"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
        &lt;h1&gt;&lt;?php echo $heading_title; ?&gt;&lt;/h1&gt;
        &lt;ul class="breadcrumb"&gt;
          &lt;?php foreach ($breadcrumbs as $breadcrumb) { ?&gt;
          &lt;li&gt;&lt;a href="&lt;?php echo $breadcrumb['href']; ?&gt;"&gt;&lt;?php echo $breadcrumb['text']; ?&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;?php } ?&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="container-fluid"&gt;
      &lt;?php if ($error_warning) { ?&gt;
      &lt;div class="alert alert-danger"&gt;&lt;i class="fa fa-exclamation-circle"&gt;&lt;/i&gt; &lt;?php echo $error_warning; ?&gt;
        &lt;button type="button" class="close" data-dismiss="alert"&gt;&amp;times;&lt;/button&gt;
      &lt;/div&gt;
      &lt;?php } ?&gt;
      &lt;div class="panel panel-default"&gt;
        &lt;div class="panel-heading"&gt;
          &lt;h3 class="panel-title"&gt;&lt;i class="fa fa-pencil"&gt;&lt;/i&gt; &lt;?php echo $text_edit; ?&gt;&lt;/h3&gt;
        &lt;/div&gt;
        &lt;div class="panel-body"&gt;
          &lt;form action="&lt;?php echo $action; ?&gt;" method="post" enctype="multipart/form-data" id="form-helloworld" class="form-horizontal"&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-sm-2 control-label" for="input-status"&gt;&lt;?php echo $entry_status; ?&gt;&lt;/label&gt;
              &lt;div class="col-sm-10"&gt;
                &lt;select name="mysite_status" id="input-status" class="form-control"&gt;
                  &lt;?php if ($mysite_status) { ?&gt;
                  &lt;option value="1" selected="selected"&gt;&lt;?php echo $text_enabled; ?&gt;&lt;/option&gt;
                  &lt;option value="0"&gt;&lt;?php echo $text_disabled; ?&gt;&lt;/option&gt;
                  &lt;?php } else { ?&gt;
                  &lt;option value="1"&gt;&lt;?php echo $text_enabled; ?&gt;&lt;/option&gt;
                  &lt;option value="0" selected="selected"&gt;&lt;?php echo $text_disabled; ?&gt;&lt;/option&gt;
                  &lt;?php } ?&gt;
                &lt;/select&gt;
              &lt;/div&gt;
            &lt;/div&gt;          
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;?php echo $footer; ?&gt;
  </code></pre>
  
  <p>When I install the module (I am developing in WAMP), I get the following error:</p>
  
  <blockquote>
    <p>Fatal error: Call to a member function get() on a non-object in H:\wamp\www\mysite.local\system\engine\controller.php on line 10</p>
  </blockquote>
  
  <p>Any ideas what this error is about? When I refresh the page, it does say the module is installed, when I try to uninstall it, I get the same error.</p>