Fatal error: Call to a member function base_url() on a non-object Codeigniter
Fatal error: Call to a member function base_url() on a non-object Codeigniter
Fatal error: Call to a member function base_url() on a non-object
当我从支付网关重定向到该站点时出现上述错误,因此包含所有脚本的头文件未加载
我尝试使用 $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;
}
您可以尝试像这样加载助手
文件名首字母大写
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');
}
}
你的问题是这一行:
$this->config = $this->config->item('payu_config');
我不知道这段代码是否在库/控制器中,所以我尝试对两者进行解释:
控制器:
您用一个配置项重写了整个配置($this->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;
}
Fatal error: Call to a member function base_url() on a non-object
当我从支付网关重定向到该站点时出现上述错误,因此包含所有脚本的头文件未加载
我尝试使用 $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;
}
您可以尝试像这样加载助手
文件名首字母大写
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');
}
}
你的问题是这一行:
$this->config = $this->config->item('payu_config');
我不知道这段代码是否在库/控制器中,所以我尝试对两者进行解释:
控制器:
您用一个配置项重写了整个配置($this->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;
}