2017-04-11 117 views
1

这里是我的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 \程序\ CONFIG \ upload.php的 行:2 功能:_error_handler

+0

在助手添加此代码,并定义'$ CI =&get_instance();'然后调用'$ CI- > URI->段(2)'。 – Gaurav

回答

0

用作其类

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

消息:未定义的属性:CI_Loader :: $ CI – Sabbir

+0

'<?php $ CI =&get_instance(); ?>''在使用前写下这一行 –

0

的得不到比如我会sugest你自动加载的URI资源

+0

可以描述如何添加自动载入uri资源,这是否正确: $ autoload ['helper'] = array('url','form','text','uri') ; – Sabbir

+0

你有在那里的网址,所以它应该工作。 – theEUG

0

您可以更改像这样

你必须让慈大师班

$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'; 
} 
+0

谢谢@ ImBS95。它的工作 – Sabbir