2017-04-11 115 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