Php CodeIgniter中库的实例数组
在CodeIgniter中加载一种库(比方说Php CodeIgniter中库的实例数组,php,arrays,codeigniter,Php,Arrays,Codeigniter,在CodeIgniter中加载一种库(比方说Student)之后,如何构造它的实例数组?据我所知,在使用$this->load->library('student')加载student库之后我可以使用$this->student访问单个学生。这是我的问题,我需要一个数组,这个学生s我如何才能做到这一点。在你的库文件中 function get_student_list() { // $uqery = SQL query to get the students - or a cal
Student
)之后,如何构造它的实例数组?据我所知,在使用$this->load->library('student')加载student
库之后
我可以使用$this->student
访问单个学生
。这是我的问题,我需要一个数组,这个学生
s我如何才能做到这一点。在你的库文件中
function get_student_list()
{
// $uqery = SQL query to get the students - or a call to your model to get them
return $query;
}
然后在你的控制器里
$list = $this->student->get_student_list();
您应该真正使用模型而不是库库用于扩展CodeIgniter的功能模型让您与数据交互;本案中的学生。使用库获取数据并对其进行实例化是对自己的打击 在您的
Student\u模型中
,您可以放置函数(从数据库或任何地方)获取数据:
此外,我建议您再看看:
function get_students() {
// Returns an array or object of all students and their info
}
function get($student_id) {
// Returns a single student's information
}
// Additional CRUD functions, if desired.