致命错误:在非对象Codeigniter上调用成员函数base_url()

时间:2016-08-09 04:49:06

标签: php codeigniter payumoney

  

致命错误:在非对象

上调用成员函数base_url()

当我从支付网关重定向到网站时出现上述错误,因此包含所有脚本的头文件无法加载

我尝试使用$ci =& get_instance();但仍然给出同样的问题

public function payment_success() { 
    $this->load->model("bidding_m"); 
    $this->load->model("admin_setting_m"); 
    $this->load->model("channel_partners_m"); //call model functions to update the tables 
    $this->load->config('payu_config', TRUE); 
    $this->config = $this->config->item('payu_config'); 
    //echo base_url();
    exit;
}

2 个答案:

答案 0 :(得分:0)

您可以尝试像这样加载帮助

文件名第一个letterupper案例

<强> Somelibraryname.php

<?php

class Somelibraryname  {

  public function __construct() {
    $this->CI =& get_instance();
    $this->CI->load->helper('url');
  }

  public function something() {
    echo base_url();

    // Or

    echo $this->CI->config->item('base_url');
  } 

}

答案 1 :(得分:0)

你的问题就在这一行:

$this->config = $this->config->item('payu_config');

我不知道这个代码是否在库/控制器中,所以我尝试解释它们:

<强>控制器:

您使用单个配置项重写整个配置($ this-&gt; config = ...),您的 base_url 配置项将丢失!所以这样做:

$config = $this->config->item('payu_config');

<强>库:

您正在访问配置项,但没有codeigniter实例。如果此代码在库中,它应如下所示:

public function payment_success() { 
    $ci = & get_instance();
    $ci->load->model("bidding_m"); 
    $ci->load->model("admin_setting_m"); 
    $ci->load->model("channel_partners_m"); 
    $ci->load->config('payu_config', TRUE); 
    //if you have in this library variable $config
    $this->config = $ci->config->item('payu_config'); 
    echo base_url();
    exit;
}