当我提交网址表单example.com/index.php/topic/1/test-topic-test
时,CodeIgniter无法识别提交的表单。
路线:
$route["topic/(:num)/([a-z]+)"]["post"] = "forums/topic_post_reply/$1/$2";
Forums.php控制器:
public function topic_post_reply($id, $name)
{
$message = $this->input->post("topic_reply_content");
if(!empty($message) && !empty($this->session->userdata('id')))
{
$data = [
"content" => $message,
"author" => $this->session->userdata('id'),
"reply_date" => time(),
"parent" => $id
];
$this->db->insert("forum_topics_replies", $data);
}
else
{
die("Something went wrong");
}
}
形式:
<form class="uk-form-stacked" action="<?php echo base_url(); ?>index.php/topic/<?php echo $this->uri->segment(2); ?>/<?php echo $this->forums_model->slug($this->uri->segment(3)); ?>" method="post">
<div class="uk-form-inline">
<textarea class="uk-textarea" name="topic_reply_content" rows="4" placeholder="Write a lovely reply..."></textarea>
</div>
<div class="laevis-reply-hidden">
<div class="uk-margin-small" style="margin-bottom:0">
<input type="submit" class="uk-button uk-button-primary uk-width-1-1" value="Post">
</div>
</div>
为什么这不起作用?
答案 0 :(得分:1)
我必须在所有其他路线之上使用相同网址的邮政路线,否则它将无效。我还必须将其更改为$route["topic/(:num)/:any"]["post"]
。