消息:未定义的属性:CI_Loader :: $ uri

时间:2017-04-11 06:33:20

标签: codeigniter upload

这是我的config / upload.php代码:

if($this->uri->segment(2)=='addPlace'){
    $config[upload_path] = './uploads/place_pic/';
    $config[allowed_types] = 'gif|jpeg|jpg|png';
}
elseif($this->uri->segment(2)=='addPack'){
    $config[upload_path] = './uploads/package_pic/';
    $config[allowed_types] = 'gif|jpeg|jpg|png';
}

运行我的项目后显示:

A PHP Error was encountered

严重性:注意

消息:未定义属性:CI_Loader :: $ uri

文件名:config / upload.php

行号:2

回溯:

文件:D:\ xampp \ htdocs \ project_tour_city \ application \ config \ upload.php 线:2 功能:_error_handler

3 个答案:

答案 0 :(得分:0)

用作未获得类

的实例
$this->CI->uri->segment('2')

答案 1 :(得分:0)

我想你自动加载URI资源

答案 2 :(得分:0)

  

你可以像这样改变

你必须得到ci大师班

$ci =& get_instance();
// after you use $ci instead of $this
if($ci->uri->segment(2)=='addPlace'){
    $config[upload_path] = './uploads/place_pic/';
    $config[allowed_types] = 'gif|jpeg|jpg|png';
}
else if($ci->uri->segment(2)=='addPack'){
    $config[upload_path] = './uploads/package_pic/';
    $config[allowed_types] = 'gif|jpeg|jpg|png';
}