2016-03-29 61 views
0

我知道這個問題已經有了答案,但是我不明白,所以再次詢問所以請大家幫忙。

這個錯誤實際上是什麼意思?

Fatal error: Using $this when not in object context in C:\wamp\www\provisioning\application\controllers\customer\provisioning.php on line 27

public function index(){ 
    $users = $this->data['tenant_users'] = $this->customer_user_m->tenant_users(); 
    $domain = $users[0]['domain']; 
    $site = $users[0]['site_key']; 
    $tenant_id = $users[0]['tenant_id']; 
    $site = $this->session->userdata('site'); 
    $user_table = $this->session->userdata('user_table'); 

    function getOTAURLExt($ext){ 
    var_dump($this); 
    } 

    function getOTAURLSite(){ 
    echo "Site executed"; 
    } 

    $this->db->select('*'); 
    $this->db->where('id', $tenant_id); 
    $this->db->from('tenant'); 
    $query = $this->db->get(); 
    $result = $query->result_array(); 

    if(empty($this->input->post('md'))){ 
    $URL = getOTAURLSite($site); 
    }else{ 

    $username = $result[0]['username']; 

    $table_user = $username . "_users"; 


    $this->db->select('*'); 
    $this->db->where($table_user . '.site_key', $site); 
    $this->db->join('mlcsites', 'mlcsites.site_key =' . $table_user . '.site_key'); 
    $this->db->from($table_user); 
    $query_table = $this->db->get(); 
    $information = $query_table->result_array(); 


    $ext = $information[0]['ext']; 


    $count = count($information); 
    $found = false; 
    for($i = 0; $i < $count; $i++){ 
     $domain = $information[$i]['domain']; 
     $ext = $information[$i]['ext']; 

     $hash = do_hash($ext . "@" . $domain, 'md5'); 

     if($hash == $this->input->post('md')){ 

     $found = true; 
     break; 
     } 
    } 

    if($found == true){ 
     $URL = getOTAURLExt($ext); 
    } 
    } 
    if(empty($URL)){ 

    } 

    $this->data['subview'] = 'provisioning/index'; 
    $this->load->view('_layout_main', $this->data); 
} 

可能是什麼可能的解決方案呢?

+0

'$ users = $ this-> data''tenant_users'] = $ this-> customer_user_m-> tenant_users();'multi assign !! –

+0

codeing for line 27在provisioning.php中? – itzmukeshy7

+0

@DavidJawphan忽略它,它應該是這樣$ this-> data ['tenant_users'] = $ this-> customer_user_m-> tenant_users();'所以我會通過tenant_users數組來查看 – Rajan

回答

0

按照您提供的代碼,似乎是在「第27行」沒有那麼恕我直言,這似乎是對「10號線」造成

function getOTAURLExt($ext){ 
    var_dump($this); // <<< This seems to be causing error. 
} 

現在,如果你需要內部的變量$this功能你可以

  1. 傳遞它作爲一個參數(如果你只需要讀取對象的值)。
  2. 通過引用傳遞它(如果需要更新對象)。
  3. 聲明全局。

...然後在函數內部使用它。

+0

你是對的,我試圖回聲$ this-> session-> userdata('site');所以我得到那個錯誤 – Rajan

相關問題