さて、私はこれを私のCodeigniterコントローラに持っています:
public function post($id) {
$data['query'] = $this->blog_model->get_post($id);
$data['comments'] = $this->blog_model->get_post_comment($id);
$data['post_id']=$id;
$data['total_comments'] = $this->blog_model->total_comments($id);
$this->load->helper('form');
$this->load->library(array('form_validation','session'));
//validation rules for post function
$this->form_validation->set_rules('commenter','Name','required');
$this->form_validation->set_rules('email','Your email','required'|'valid_email');
$this->form_validation->set_rules('comment','Comment','required');
if($this->blog_model->get_post($id))
{
foreach($this->blog_model->get_post($id) as $row)
{
//set page title
$data['title'] = $row->entry_name;
}
if($this->form_validation->run() == FALSE)
{
//if validation runs FALSE
$this->load->view('blog/post',$data);
}
else
{
//if valid
$name = $this->input->post('comment_name');
$email = strtolower($this->input->post('comment_email'));
$comment = $this->input->post('comment_body');
$post_id = $this->input->post('entry_id');
$this->blog_model->add_new_comment($post_id,$name,$email,$comment);
$this->session->set_flashdata('message', '1 new comment added!');
redirect('post/'.$id);
}
}
else
show_404();
}
私の投稿ビューにはこれがあります:
echo form_open('blog/post'.$id);
$id
URLに入力した変数を、コメントフォームの投稿ビューに渡したいです。$id
変数をビューに渡すにはどうすればよいですか?