我的模型错误:调用未定义的方法CI_DB_mysqli_driver :: result()
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class teacher_feedback extends CI_Model {
public function teacher_feedback_query($teacher)
{
$teacher_feedback_query = 'SELECT TD.name, TD.subject, TFA.answer_value, SBI.first_name, TFSAC.comment, TFSC.comment, TFQ.teachers_feedback_question_id FROM teacher_details as TD inner join teachers_feedback_student_answer as TFSA on TFSA.teacher_id = TD.teacher_id inner join teachers_feedback_answer as TFA on TFA.teachers_feedback_answer_id = TFSA.teachers_feedback_answer_id inner join teachers_feedback_student_answer_comment as TFSAC on TFSAC.teacher_id = TD.teacher_id inner join student_basic_info as SBI on SBI.student_id=TFSAC.student_id inner join teachers_feedback_student_comment as TFSC on TFSC.student_id = SBI.student_id inner join teachers_feedback_question as TFQ on TFQ.teachers_feedback_question_id = TFSA.teachers_feedback_question_id where TD.teacher_id = ?';
$teacher_query = $this->db->query($teacher_feedback_query,array($teacher));
$teacher_feedback_result = $this->db->result($teacher_query);
return $teacher_feedback_result();
}
}
?>
答案 0 :(得分:1)
尝试返回result_array()而不仅仅是result()
答案 1 :(得分:1)
我认为你在这里想做的事情是错误的。应该对查询结果调用result
方法,而不是db
对象。
试试这个:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class teacher_feedback extends CI_Model {
public function teacher_feedback_query($teacher)
{
$teacher_feedback_query = 'SELECT TD.name, TD.subject, TFA.answer_value, SBI.first_name, TFSAC.comment, TFSC.comment, TFQ.teachers_feedback_question_id FROM teacher_details as TD inner join teachers_feedback_student_answer as TFSA on TFSA.teacher_id = TD.teacher_id inner join teachers_feedback_answer as TFA on TFA.teachers_feedback_answer_id = TFSA.teachers_feedback_answer_id inner join teachers_feedback_student_answer_comment as TFSAC on TFSAC.teacher_id = TD.teacher_id inner join student_basic_info as SBI on SBI.student_id=TFSAC.student_id inner join teachers_feedback_student_comment as TFSC on TFSC.student_id = SBI.student_id inner join teachers_feedback_question as TFQ on TFQ.teachers_feedback_question_id = TFSA.teachers_feedback_question_id where TD.teacher_id = ?';
$teacher_query = $this->db->query($teacher_feedback_query,array($teacher));
//$teacher_feedback_result = $this->db->result($teacher_query);
$teacher_feedback_result = $teacher_query->result();
return $teacher_feedback_result; // Remove parenthesis, $teacher_feedback_result is not a function
}
}
?>
修改强>
关于错误调用未定义的方法CI_DB_mysqli_driver :: result()
PHP抛出此错误,因为CodeIgniter MySQLi适配器类没有方法result
。这是CodeIgniter MySQLi驱动程序类。您可以检查一下,没有这样的方法result
:
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/drivers/mysqli/mysqli_driver.php
因此,当您致电$this->db->result($teacher_query)
时,$this->db
会附加到CI_DB_mysqli_driver
,因此您会收到一个错误,即您正在调用未定义的方法。
答案 2 :(得分:0)
在大多数情况下,由于我们在上面应用了核心php代码,而ci有其自己的应用方式,因此会出现此类错误。 因此,有时我们成功地应用了一些核心代码,但有时却没有。 在这种情况下,请尝试继续使用ci doc,您很可能会找到解决方案。 祝你好运。