我有Model_User
// Get Exams by User
public static function get_exam_by_user($user_id) {
$query = "SELECT e.exam_id, e.exam_code, e.exam_name, e.description, e.creator, e.password,
e.max_attempt, e.random_order, e.max_time, e.max_score, e.min_score, e.grading,
e.created_at, e.updated_at
FROM exam e, user_exam ue
WHERE ue.exam_id = e.exam_id
AND ue.status = 1
AND ue.user_id = :user_id";
$result = DB::query($query)->bind('user_id', $user_id)->execute();
return $result->as_array();
}
和这个控制器
public function action_index() {
$data = array();
//$data['user_id'] = \Auth\Auth::get('id');
//$data['username'] = \Auth\Auth::get('username');
$user_id = Auth\Auth::get('id');
//$data['exams'] = Model_Exam::find('all');
$data['exams'] = Model_Exam::get_exam_by_user($user_id);
$this->template->title = "Exams";
$this->template->content = View::forge('admin/exam/index', $data);
}
如何预测视图?我尝试使用printr_r
Array ( [0] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) [1] => Array ( [exam_id] => 2 [exam_code] => SD_K1S1_MAT [exam_name] => Ujian Matematika SD Kelas 1 Sem 1 [description] => [creator] => RF [password] => [max_attempt] => 3 [random_order] => 1 [max_time] => 60 [max_score] => 100 [min_score] => 0 [grading] => [created_at] => 2013 [updated_at] => 2013 ) )
如果你能帮忙解决这个问题
答案 0 :(得分:1)
我认为你可以这样做:
<?php foreach ($exams as $exam):
echo $exam['exam_id'];
echo $exam['exam_code'];
echo $exam['exam_name']; .... and so on....
希望就是你所需要的。