【问题标题】:Submit form using Codeigniter URI Routing not work使用 Codeigniter URI 路由提交表单不起作用
【发布时间】:2018-08-23 10:04:44
【问题描述】:

我必须用论坛更新一个不是我创建的网站。该站点是使用 codeigniter 的最新版本创建的。 我是路由 uri 的新手。

当我提交表单时,出现错误“404 The page you request was not found”。 我要执行的方法 add_post() 在 Admin_adherent_forum_C 类中。此类位于 controllers/admin_adherent 文件夹中。 路线有问题,但我不知道是什么?

HTML:

<form action="<?=base_url('espace-adherent/forum/creer_sujet.html')?>" method="post" enctype="multipart/form-data">
      <div class="CreateSubjectHeader">
        <p>Nouveau sujet</p><a href=".CreateSubject" id="openButtonSubject">+</a><a id="closeButtonSubject">-</a>
      </div>
      <div id="contentSubject">
        <div class="CreateSubject">
          <div class="CreateSubjectTitle">
            <label>Titre :</label>
            <input type="text" name="sujet" value="" required>
          </div>
          <div class="CreateSubjectContent">
            <label>Texte :</label>
            <textarea name="discussion" required></textarea>
          </div>
          <div class="CreateSubjectCategory">
            <label>Catégorie :</label>
            <select id="selectCategory" class="categorie" name="categorie[]" multiple>
              <option value="1">Entreprise</option>
              <option value="2">Collaborateurs</option>
              <option value="3">Recyclage</option>
              <option value="4">Valorisation</option>
              <option value="5">Aménagement</option>
            </select>
          </div>
        </div>
        <div class="CreateSubjectFooter">
          <img class="FileIcon" src="/img/file_icon.svg" alt="">
          <input id="file" class="FileInput" type="file" name="fichier_sujet" value="">
          <input class="SubmitButton" type="submit" name="publier" value="Publier">
        </div>
      </div>
    </form>

PHP:

defined('BASEPATH') OR exit('No direct script access allowed');

  class Admin_adherent_forum_C extends CI_Controller {
   public function add_post()
    {
      my code here...
    }
  }

路线:

$route['espace-adherent/forum/creer_sujet']= 'admin_adherent/Admin_adherent_forum_C/add_post';

【问题讨论】:

  • 您的表单操作 url 与路由路径不匹配
  • 谢谢解答,贴错了。我尝试将 url 与路由路径匹配,但这是相同的错误。

标签: php codeigniter codeigniter-3


【解决方案1】:

在表单动作中用这个改变 URL。

base_url('espace-adherent/forum/creer_sujet');

【讨论】:

  • 谢谢解答,贴错了。我尝试将 url 与路由路径匹配,但这是相同的错误。
  • 发生了什么?
  • 总是同样的错误“404 找不到您请求的页面”。我用正确的路线更新我的帖子。 $route['espace-adherent/forum/creer_sujet']='admin_adherent/Admin_adherent_forum_C/add_post
  • 谢谢,我试试。现在我有一个白页,没有插入任何内容。
【解决方案2】:

在表单动作中

中给出的URL

base_url('espace-adherent/forum/creer_sujet.html')

但是里面配置的网址是

$route['espace-adherent/forum/add_post']= 'admin_adherent/Admin_adherent_forum_C/add_post';

更新:请尝试从表单操作中删除 .html

希望它有效。谢谢

【讨论】:

  • 谢谢解答,贴错了。我尝试将 url 与路由路径匹配,但这是相同的错误。
  • 我用正确的路线更新我的帖子。 $route['espace-adherent/forum/creer_sujet']='admin_adherent/Admin_adherent_forum_C/add_post';
【解决方案3】:

问题解决了。它来自 .htaccess 重写模式。我不知道如何以及为什么,但它被禁用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 2011-11-07
    相关资源
    最近更新 更多