dongqu4443
2018-01-28 15:54
浏览 261
已采纳

CodeIgniter没有对帖子做出反应

When I submit a form for the url example.com/index.php/topic/1/test-topic-test CodeIgniter does not recognize that a post form is submitted.

Routes:

$route["topic/(:num)/([a-z]+)"]["post"] = "forums/topic_post_reply/$1/$2";

Forums.php controller:

    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:

<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>

Why isn't this working?

图片转代码服务由CSDN问答提供 功能建议

当我提交网址 example.com/index.php/topic/1/test的表单时 -topic-test CodeIgniter无法识别提交的帖子。

路由:

  $ route [“  topic /(:num)/([az] +)“] [”post“] =”forums / topic_post_reply / $ 1 / $ 2“; 
   
 
 

论坛。 php控制器:

  public function topic_post_reply($ id,$ name)
 {
 $ message = $ this-&gt; input-&gt; post(“topic_reply_content”)  ; 
 if(!empty($ message)&amp;&amp;!empty($ this-&gt; session-&gt; userdata('id')))
 {
 $ data = [
“content”=  &GT;  $ message,
“author”=&gt;  $ this-&gt; session-&gt; userdata('id'),
“reply_date”=&gt;  time(),
“parent”=&gt;  $ id 
]; 
 
 $ this-&gt; db-&gt; insert(“forum_topics_replies”,$ data); 
} 
 else 
 {
 die(“Something failed”); \ 表格: 
 
 
 &lt; form class =“uk-form-stacked”  action =“&lt;?php echo base_url();?&gt; index.php / topic /&lt;?php echo $ this-&gt; uri-&gt; segment(2);?&gt; /&lt;?php echo $  this-&gt; forums_model-&gt; slug($ this-&gt; uri-&gt; segment(3));?&gt;“  method =“post”&gt; 
&lt; div class =“uk-form-inline”&gt; 
&lt; textarea class =“uk-textarea”name =“topic_reply_content”rows =“4”placeholder =“写一个可爱的 回复...“&gt;&lt; / textarea&gt; 
&lt; / div&gt; 
 
&lt; div class =”laevis-reply-hidden“&gt; 
&lt; div class =”uk-margin-small“style  =“margin-bottom:0”&gt; 
&lt; input type =“submit”class =“uk-button uk-button-primary uk-width-1-1”value =“Post”&gt; 
&lt;  / div&gt; 
&lt; / div&gt; 
   
 
 

为什么这不起作用?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulouli8686 2018-01-28 16:38
    已采纳

    I had to have the post route above all other routes for the same url or it would not work. I also had to change it to $route["topic/(:num)/:any"]["post"].

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题