2012-02-02 6 views
0

私のモデルには2つのメソッドがあります。 1つはデータを選択してコントローラ(public)に返し、もう1つのメソッド(プライベート)はデータベースからデータを選択してパブリックメソッドに返します。DBから選択するとCodeIgniterの未定義インデックス

これは私のパブリックメソッドです。

public function get_template() 
{ 
    // Get the active config. 
    $config_id = $this->get_config(); 

    // Prepare the SQL query. 
    $this->db->select('template'); 
    $this->db->from('tms_config'); 
    $this->db->where('config_id',$config_id); 
    $this->db->limit(1); 

    // Execute the query. 
    $query = $this->db->get(); 

    // Get the result. 
    $result = $query->row_array(); 

    // Make sure a template is set. 
    if (! empty($result['template'])) 
    { 
     return $result['template']; 
    } 
    else 
    { 
     // Return the default template. 
     return DEFAULT_TEMPLATE; 
    } 
} 

次にプライベートメソッド。

private function get_config() 
{ 
    // Prepare the SQL query. 
    $this->db->select('config_id'); 
    $this->db->from('tms_config'); 
    $this->db->where('active',1); 
    $this->db->limit(1); 

    // Execute the query. 
    $query = $this->db->get(); 

    // Get the result. 
    $result = $query->row_array(); 

    // Return the configuration ID. 
    return $result['config_id']; 
} 

はどうやら何かが公共の方法で$config_idとして、間違って起こっていることは空です。 このエラーが表示されます。

A PHP Error was encountered 
Severity: Notice 
Message: Undefined index: config_id 
Filename: models/tms_config.php 
Line Number: 140 

行140は、get_config()メソッドの戻り行です。

誰でも私にこのことを教えてもらえますか? ありがとうございます。

+1

は$結果[ 'CONFIG_ID']定義されてみては? $ result = $ query-> row_array()の後にprint_r($ result)を試してください。 – IsisCode

+0

配列が空でした。問題は、私の質問で1を '1'に変更しなければならないということでした。 – Roel

答えて

2

この

$result = $query->result_array(); 
return $result[0]['config_id']; 
関連する問題