【问题标题】:Getting remarks of teacher and principal in view听取老师和校长的意见
【发布时间】:2019-12-06 06:20:40
【问题描述】:

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

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

现在,这些 cmets 出现在学生的视野中,但我很难让它出现在家长的视野中。

这是模型:

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>

【问题讨论】:

  • 大部分 PHP 看起来与这个问题无关(例如 TeacherComment()UpdateTeacherComment()PrincipalComment()UpdatePrincipalComment())——如果你能坚持下去,你将有更好的机会帮助人们你的问题简单而集中。您如何调用视图并将您的$data 传递给它,您可以编辑您的问题并显示它吗?另外,只是为了检查一下 - 你确定有 cmets要显示吗?

标签: codeigniter model-view-controller


【解决方案1】:

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

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

【讨论】:

  • 有了这个,我得到数字“1”作为 cmets 而不是实际的 cmets
最近更新 更多