codeigniter - 听取老师和校长的意见
问题描述
我试图让老师和校长的评论出现在视野中,但无济于事。
这是一个学校网络应用程序,家长可以在其中查看各自孩子的成绩。分数下方是老师和校长的评论。
现在,这些评论出现在学生的观点中,但我很难让它出现在父母的观点中。
这是模型:
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>
解决方案
假设这是您的控制器文件。
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
推荐阅读
- common-lisp - 如何使用管道将二进制文件发送到 Lisp 进程?
- ubuntu - Ubuntu Kernel Panic - 不同步;试图杀死 init !退出代码=0x0000000b
- oracle11g - Oracle:存储过程中批量收集游标的动态表名
- c++ - 如何在调试故障转储时设置断点?
- alsa - 为什么 ALSA snd_pcm_hw_params_get_buffer_size 会对本地堆栈帧分配的大小做出反应?
- python-3.8 - 以编程方式安装后未导入 Python 模块
- reactjs - 部署了一个反应项目。它只显示一个空白页面而不是项目
- python - 在 Ubuntu 16.04 LTS 上使用 pgadmin4.15 和 apache 时出现内部服务器错误
- javascript - 使用胖箭头函数更改 React-Native 中的 React.Component
- spring-boot - Spring webflux jpa事务