【问题标题】:Message: Undefined property: CI_Loader::$uri消息:未定义的属性:CI_Loader::$uri
【发布时间】:2017-09-06 09:28:00
【问题描述】:

这是我的 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

【问题讨论】:

  • 在助手中添加这段代码并定义$CI = &get_instance();然后调用$CI->uri->segment(2)

标签: codeigniter upload


【解决方案1】:

用作它没有获取类的实例

$this->CI->uri->segment('2')

【讨论】:

  • 消息:未定义的属性:CI_Loader::$CI
  • <?php $CI =& get_instance(); ?>使用前写下这一行
【解决方案2】:

我建议你自动加载 URI 资源

【讨论】:

  • 你能描述一下如何添加自动加载 uri 资源吗,正确吗:$autoload['helper'] = array('url', 'form', 'text' , 'uri');跨度>
【解决方案3】:

你可以这样改变

你必须获得 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';
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多