简体   繁体   English

自定义打开购物车模块安装-致命错误:在非对象上调用成员函数get()

[英]Custom open cart module install - Fatal error: Call to a member function get() on a non-object

I am trying to write a custom module that will hook into post.order.history.add event and do a custom action. 我正在尝试编写一个自定义模块,该模块将挂接到post.order.history.add事件中并执行自定义操作。 This is my module structure & code so far: 到目前为止,这是我的模块结构和代码:

admin\\controller\\module\\mysite.php 管理员\\控制器\\模块\\ mysite.php

<?php

class ControllerModuleMysite extends Controller
{
    private $error;
    private $logger;

    public function __construct()
    {
        $this->error  = array();
        $this->logger = new Log('MySite.log');
    }

    /* Event Hooks */

    public function install()
    {
        $this->load->model('extension/event');

        $this->model_extension_event->addEvent('mysite_NewOrder', 'post.order.history.add', 'module/mysite/on_order_history_add');
    }

    public function uninstall()
    {
        $this->load->model('extension/event');

        $this->model_extension_event->deleteEvent('mysite_NewOrder');
    }

    /* Admin Config Handler */

    public function index()
    {
        // Loading the language file of mysite
        $this->load->language('module/mysite');

        // Set the title of the page to the heading title in the Language file
        $this->document->setTitle($this->language->get('heading_title'));

        // Load the Setting Model  (All of the OpenCart Module & General Settings are saved using this Model )
        $this->load->model('setting/setting');

        // Start If: Validates and check if data is coming by save (POST) method
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate())
        {
            // Parse all the coming data to Setting Model to save it in database.
            $this->model_setting_setting->editSetting('mysite', $this->request->post);

            // To display the success text on data save
            $this->session->data['success'] = $this->language->get('text_success');

            // Redirect to the Module Listing
            $this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
        }

        // Assign the language data for parsing it to view
        $data['heading_title'] = $this->language->get('heading_title');

        $data['text_edit']           = $this->language->get('text_edit');
        $data['text_enabled']        = $this->language->get('text_enabled');
        $data['text_disabled']       = $this->language->get('text_disabled');
        $data['text_content_top']    = $this->language->get('text_content_top');
        $data['text_content_bottom'] = $this->language->get('text_content_bottom');
        $data['text_column_left']    = $this->language->get('text_column_left');
        $data['text_column_right']   = $this->language->get('text_column_right');

        $data['entry_code']       = $this->language->get('entry_code');
        $data['entry_layout']     = $this->language->get('entry_layout');
        $data['entry_position']   = $this->language->get('entry_position');
        $data['entry_status']     = $this->language->get('entry_status');
        $data['entry_sort_order'] = $this->language->get('entry_sort_order');

        $data['button_save']       = $this->language->get('button_save');
        $data['button_cancel']     = $this->language->get('button_cancel');
        $data['button_add_module'] = $this->language->get('button_add_module');
        $data['button_remove']     = $this->language->get('button_remove');

        // This Block returns the warning if any
        if (isset($this->error['warning'])) {
            $data['error_warning'] = $this->error['warning'];
        } else {
            $data['error_warning'] = '';
        }

        // This Block returns the error code if any
        if (isset($this->error['code'])) {
            $data['error_code'] = $this->error['code'];
        } else {
            $data['error_code'] = '';
        }

        // Making of Breadcrumbs to be displayed on site
        $data['breadcrumbs']   = array();
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => false
        );
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_module'),
            'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );
        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('module/mysite', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => ' :: '
        );

        $data['action'] = $this->url->link('module/mysite', 'token=' . $this->session->data['token'], 'SSL');

        $data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

        // This block parses the status (enabled / disabled)
        if (isset($this->request->post['mysite_status'])) {
            $data['mysite_status'] = $this->request->post['mysite_status'];
        } else {
            $data['mysite_status'] = $this->config->get('mysite_status');
        }

        $data['header']      = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer']      = $this->load->controller('common/footer');

        $this->response->setOutput($this->load->view('module/mysite.tpl', $data));

    }

    protected function validate()
    {
        // Block to check the user permission to manipulate the module
        if (!$this->user->hasPermission('modify', 'module/mysite')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        // Block returns true if no error is found, else false if any error detected
        if (!$this->error) {
            return true;
        } else {
            return false;
        }
    }

    /* Event Handlers */

    public function on_order_history_add($order_id)
    {
        // Load order data
        $this->load->model('checkout/order');
        $orderData = $this->model_checkout_order->getOrder($order_id);

        // Debug
        $this->logger->write(print_r($orderData, true));

        // TODO: call third-party api & create hosting package
        // TODO: send success/error email notification to customer
    }
}

admin\\language\\english\\module\\mysite.php 管理员\\语言\\英语\\模块\\ mysite.php

<?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';

admin\\view\\template\\module\\mysite.tpl 管理员\\视图\\模板\\模块\\ mysite.tpl

<?php echo $header; ?><?php echo $column_left; ?>

<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-helloworld" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1><?php echo $heading_title; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
      </div>
      <div class="panel-body">
        <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-helloworld" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
            <div class="col-sm-10">
              <select name="mysite_status" id="input-status" class="form-control">
                <?php if ($mysite_status) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select>
            </div>
          </div>          
        </form>
      </div>
    </div>
  </div>
</div>

<?php echo $footer; ?>

When I install the module (I am developing in WAMP), I get the following error: 当我安装模块(我正在WAMP中进行开发)时,出现以下错误:

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 致命错误:在第10行的H:\\ wamp \\ www \\ mysite.local \\ system \\ engine \\ controller.php中的非对象上调用成员函数get()

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. 当我刷新页面时,它确实说模块已安装,当我尝试将其卸载时,会出现相同的错误。

The original constructor was setting up the $this->registry object. 最初的构造函数正在设置$this->registry对象。 You are overriding the constructor ( system/engine/controller.php:2 ). 您正在重写构造函数( system/engine/controller.php:2 )。 So use 所以用

public function __construct($registry)
  {
     parent::__construct( $registry );
     $this->error  = array();
     $this->logger = new Log('MySite.log');
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Joomla 2.5模块问题,PHP致命错误在非对象上调用成员函数get() - Joomla 2.5 Module issues, PHP Fatal Error Call to a member function get() on a non-object 致命错误:在第413行的/functions.php中的非对象上调用成员函数get_cart_contents_count() - Fatal error: Call to a member function get_cart_contents_count() on a non-object in /functions.php on line 413 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object 全新安装后,Joomla 2.5.11错误:致命错误:在非对象上调用成员函数setDebug() - Joomla 2.5.11 error after fresh install: Fatal error: Call to a member function setDebug() on a non-object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object CakePHP致命错误调用非对象上的成员函数schema() - CakePHP Fatal Error Call to a member function schema() on a non-object 致命错误:在非对象上调用成员函数 getElementsByTagName() - Fatal error: Call to a member function getElementsByTagName() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM