首页 > 解决方案 > 听取老师和校长的意见

问题描述

我试图让老师和校长的评论出现在视野中,但无济于事。

这是一个学校网络应用程序,家长可以在其中查看各自孩子的成绩。分数下方是老师和校长的评论。

现在,这些评论出现在学生的观点中,但我很难让它出现在父母的观点中。

这是模型:

Comment_model.php

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Comment_model extends CI_Model {

    public function __construct() {
        parent::__construct();
        $this->current_session = $this->setting_model->getCurrentSession();
        $this->current_session_name = $this->setting_model->getCurrentSessionName();
        $this->start_month = $this->setting_model->getStartMonth();
    }

    public function TeacherComment($data) 
    {
        $this->db->insert('teacher_comments', $data);
        return $query = $this->db->affected_rows();
    }

    public function  UpdateTeacherComment($data, $id)
    {
        $this->db->where('id', $id);
        $this->db->update('teacher_comments', $data);
        return $query = $this->db->affected_rows();
    }

    public function GetTeacherComment($student_id, $session_id) 
    {
        $this->db->select('*');
        $this->db->where('student_id', $student_id);
        $this->db->where('session_id', $session_id);
        return $this->db->get('teacher_comments')->row();
    }

    public function PrincipalComment($data) 
    {
        $this->db->insert('principal_comments', $data);
        return  $this->db->affected_rows();
    }

    public function  UpdatePrincipalComment($data, $id)
    {
        $this->db->where('id', $id);
        $this->db->update('principal_comments', $data);
        return $query = $this->db->affected_rows();
    }

    public function GetPrincipalComment($student_id, $session_id) 
    {
        $this->db->select('*');
        $this->db->where('student_id', $student_id);
        $this->db->where('session_id', $session_id);
        return $this->db->get('principal_comments')->row();
    }
}

我正在与之战斗的控制器:

$data['teacher_comment'] = $this->Comment_model->GetTeacherComment($id, $student_session_id);

$data['principal_comment'] = $this->Comment_model->GetPrincipalComment($id, $student_session_id);

如何正确使用它?

风景:

<span> CLASS TEACHER'S REMARK: 
<u style="text-transform: uppercase;"><?php echo $teacher_comment->teacher_comment; ?> </u>
</span><br>

<br>
<span>PRINCIPAL REMARK: 
<u style="text-transform: uppercase;"><?php echo $principal_comment->principal_comment; ?></u> 
</span>

标签: codeignitermodel-view-controller

解决方案


假设这是您的控制器文件。

class customview extends CI_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->load->model("Comment_model");
    }

    public function yourViewFunction()
    {
        // get your $id and $student_session_id
        $data['teacher_comment'] = $this->Comment_model->GetTeacherComment($id, $student_session_id);
        $data['principal_comment'] = $this->Comment_model->GetPrincipalComment($id, $student_session_id);
        $this->load->view('your_html_view',$data); //this is the view file name without php 
    }
}

现在在您的 html 视图中,您可以这样调用:

print_r($teacher_comment); //you can view the array or object get from model
print_r($principal_comment); //you can view the array or object get from model

推荐阅读