-2

代码在第 8、9、10、11 行的控制器中显示错误,试图获取非对象的属性。
//检查所有列名和表名。

我的模型是

public function getEducationDetail($educationID) {
    $this->db->select('qual_id,pass_year,institute,percentage,emp_id');
    $this->db->from('emp_edu');
    $this->db->where('edu_id', $educationID);
    $this->db->where('del_flag', 0);
    $query = $this->db->get();
    if ($query->num_rows() > 0):
        return $query->result();
    else:
        return 0;
    endif;
}

我的控制器是

 public function getEducationDetail() {

    $this->load->model('mod_admin');
    if (isset($_GET['param'])):
        $educationID = $this->input->get('param');
        $result = $this->mod_admin->getEducationDetail($educationID);
        $jsonArr = array(
            'qualificationID' => $result->qual_id,
            'passOut' => $result->pass_out,
            'institute' => $result->institute,
            'percentage' => $result->percentage
        );
    endif;
    $json = json_encode(array('result' => $jsonArr));
    echo $json;
}
4

3 回答 3

3

如果您的模型返回单行$query->row(),那么

$result = $this->mod_admin->getEducationDetail($educationID);
if (!empty($result)) {
    $jsonArr = array(
        'qualificationID' => $result->qual_id,
        'passOut' => $result->pass_out,
        'institute' => $result->institute,
        'percentage' => $result->percentage
    );
}

如果它返回多行$query->result()然后

$results = $this->mod_admin->getEducationDetail($educationID);

$jsonArr = array();

if (!empty($results)) {
    foreach ($results as $result) {
        $jsonArr[] = array(
            'qualificationID' => $result->qual_id,
            'passOut' => $result->pass_out,
            'institute' => $result->institute,
            'percentage' => $result->percentage
        );
    }
}

希望这可以帮助。

于 2013-02-22T05:56:49.537 回答
2

返回$query->result()它将给出多维数组。我想你会得到一个结果。将其更改为return $query->row()

于 2013-02-22T05:57:52.577 回答
0

模型

public function getEducationDetail($educationID) {
    $this->db->select('qual_id,pass_year,institute,percentage,emp_id');
    $this->db->where('edu_id', $educationID);
    $this->db->where('del_flag', 0);
    $query = $this->db->get('emp_edu');

       return $query->row();

}

控制器

public function getEducationDetail() {

$this->load->model('mod_admin');
if (isset($_GET['param'])):
    $educationID = $this->input->get('param');
    $result = $this->mod_admin->getEducationDetail($educationID);
if($result){
    $jsonArr = array(
        'qualificationID' => $result->qual_id,
        'passOut' => $result->pass_out,
        'institute' => $result->institute,
        'percentage' => $result->percentage
    );
$json = json_encode(array('result' => $jsonArr));
echo $json;
endif;
   }
}
于 2013-02-22T06:12:12.900 回答