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?

  • 写回答

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"].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 antv g6 力导向图布局
  • ¥15 各位为什么总是报错attributeerror呢,报nonetype object has no attribute group
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题
  • ¥15 matlab基于鲸鱼算法优化vmd