0
내 모델에 두 가지 방법이 있습니다. 하나는 컨트롤러 (public)로 데이터를 선택하여 반환하고 다른 하나는 (private) 데이터베이스에서 데이터를 선택하여 public 메서드로 반환하는 것입니다.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()
메소드의 리턴 라인입니다.
누구든지 나를 도와 줄 수 있습니까? 미리 감사드립니다.
이 $ 결과 [ 'config_id'] 정의하려고? $ result = $ query-> row_array(); 뒤에 print_r ($ result)을 시도해보십시오. – IsisCode
배열이 비어 있습니다. 문제는 내 쿼리에서 1을 '1'로 변경해야한다는 것입니다. – Roel