我提出了问题,我创建了一个表“评论”然后我制作了一个控制器,它实现了两个功能,读取功能和另一个插入功能。
我现在需要的是实现管理评论的功能,即在每个评论旁边都有一个选项删除和修改。
所以,我添加了一个名为manage()的新函数,然后,为了避免重复,我认为保持读取(用于列出注释)并将其用于manage()然后添加这些stufs(修改,删除)在每个评论旁边。 但我不知道该怎么办? 我需要你的建议帮助!
<?php
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
// Chargement des ressources pour tout le contrôleur
$this->load->database();
$this->load->helper('url');
$this->load->model('comments_model', 'livreorManager');
}
function index() {
$this->read();
// $this->add();
}
function read() {
$this->load->library('pagination');
$this->load->library('table');
$this->load->library('mytable');
$config['base_url'] = 'http://localhost/ci/index.php/site/index';
$config['total_rows'] = $this->db->get('comments')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 20;
$tmpl = array ( 'table_open' => '<table class="table table-striped">' );
$this->table->set_template($tmpl);
$config['full_tag_open'] = '<div class="pagination"><ul>';
$config['full_tag_close'] = '</ul></div>';
$this->pagination->initialize($config);
$this->db->order_by("id", "desc");
$data['records'] = $this->db->get('comments',$config['per_page'],$this->uri->segment(3));
$data['donnees'] = $data['records']->result_array();
$this->load->view('site_view', $data);
}
function add() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<p class="form_erreur">', '</p>');
$this->form_validation->set_rules('pseudo', '"Pseudo"', 'trim|required|min_length[3]|max_length[25]|alpha_dash');
$this->form_validation->set_rules('comment', '"Comment"', 'trim|required|min_length[3]|max_length[3000]');
if($this->form_validation->run()) {
$this->livreorManager->add_comment($this->input->post('pseudo'),$this->input->post('comment'));
$this->load->view('success');
$this->read();
}
else {
$this->load->view('add');
}
}
function manage() {
// implément options into read
$this->read();
}
}