【问题标题】:CodeIgniter: form's action cannot direct to the right pathCodeIgniter:表单的动作不能指向正确的路径
【发布时间】:2016-09-26 12:13:03
【问题描述】:

正如标题所说,我的表单的动作似乎无法指向它的路径, 这是我的表格:

form action="<?php echo site_url();?>home/search_result_t/?">
   ...
</form

所以它应该指向

example.com/index.php?/home/search_result_t/?from=&to=May+28%2C+Sat

它没有转到那个链接,而是刷新了我的主页 (example.com),我的 CI 将它定向到

example.com/index.php??from=&to=May+28%2C+Sat

好像它无法捕获我的控制器功能

有什么建议吗? 顺便说一句,我在 nginx 上运行我的 CI 这是 config.php 配置

$config['base_url'] = 'http://www.example.com/';
$config['index_page'] = 'index.php?';
$config['uri_protocol'] = 'AUTO';

【问题讨论】:

  • 这样写表单动作
    ...
  • 还是同样的问题...它只是刷新页面
  • 您在链接之前看到 HTML 代码了吗?是否在form 元素中显示例外地址?
  • 如果点击表单时页面正在刷新,则可能是路由配置或.htaccess有问题
  • 我使用的是 nginx,所以 htaccess 显然不起作用,因为它只能在 apache 上运行

标签: php forms codeigniter


【解决方案1】:

你的操作是错误的,像这样使用它

<form action="<?php echo site_url("home/search_result_t");?>" method="get" >
   ...
</form>

【讨论】:

  • 还是同样的问题...它只是刷新页面
  • 你有一个名为home的控制器和一个名为search_result_t的函数吗?也发布你的路线和你的功能太......
【解决方案2】:

如果您使用的是 codeigniter,为什么不使用 codeigniter 表单?

<?php
        $attr = [
        "id" => "ajax"
        ];
        echo form_open('home/search_result_t', $attr);

home 是您的控制器,而 search_result_t 是您在该控制器中的函数。它会自动将其定向到正确的控制器

如果您的表单没有使用 id,则不需要数组。只需使用

echo form_open('home/search_result_t');

【讨论】:

    猜你喜欢
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多