【问题标题】:codeigniter 2.1.0 Routing difficultiescodeigniter 2.1.0 路由困难
【发布时间】:2012-04-24 21:27:10
【问题描述】:

我不能用

加载控制器
http://localhost/index.php?controller/method

但如果我不使用'?'并尝试从视图中加载控制器,然后生成重复的 URL。 作为上面的示例,如果我在视图中的表单操作中添加此链接,则结果 url 将是

http://localhost/index.php/controller/index.php/controller/method

如何解决?我没有使用htaccess文件

【问题讨论】:

  • 你在 config.php 中设置了 base_url() 吗?
  • 是的。应该是localhost/codeigniter_folder_name吧?
  • 是的,它有效。但是,如果我将其设置为表单操作,它会调用 index.php/controller/index.php/controller/method 。和 '?'不工作
  • 你的表格是不是像这样打开的:form_open('controller/method');

标签: codeigniter-2


【解决方案1】:

使用site_url() 函数,或者如@JohnFable 所述,使用form_open 函数。

<form method="post" action="<?= form_open('controller/method'); ?>">

<a href="<?= site_url('controller/method'); ?>">Controller/Method</a>

<?= form_open('controller/method'); ?>

这将确保您的“基本网址”(即http://localhost)正确地添加到您要查看的网址前,即http://localhost/index.php/controller/method,或者如果您已将其设置为http://localhost/controller/method

加文

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 2010-11-20
    • 2011-07-08
    相关资源
    最近更新 更多