gpt4 book ai didi

php - 如何将变量传递给 id 变量

转载 作者:行者123 更新时间:2023-12-04 18:13:41 25 4
gpt4 key购买 nike

好的,我的 Codeigniter Controller 中有这个:

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();
}

在我的帖 subview 中,我有这个:
echo form_open('blog/post'.$id);

我想通过 $id我在 URL 中输入的变量,用于评论表单的帖 subview 。我如何通过 $id View 变量?

最佳答案

您正在通过 编号 在您的数据数组中,这里:

$data['post_id']=$id;

在你看来,而不是 $id只需使用 $post_id :
echo form_open('blog/post'.$post_id);

关于php - 如何将变量传递给 id 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12124226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com