【问题标题】:Codeigniter Redirect not workingCodeigniter 重定向不起作用
【发布时间】:2013-11-20 10:26:36
【问题描述】:

让我在以下位置

http://localhost/ignitershop/index.php/seller_controller/viewcart

在这个视图中,我有一个链接,使用它我想移动到同一个控制器的另一个方法,称为 removeRow() 。所以我使用href如下

<a href="seller_controller/removeRow" >CLICK TO REMOVE </a>

所以我希望新的网址是:

http://localhost/ignitershop/index.php/seller_controller/removeRow

但 url 似乎是连接的。它正在变成如下内容:

http://localhost/ignitershop/index.php/seller_controller/seller_controller/removeRow

也就是说,seller_controller 来了两次。我也面临着使用重定向的这种类型的连接问题。所以我需要知道什么是同一控制器切换方法的最佳方式。有什么好的解决办法???

【问题讨论】:

    标签: php codeigniter redirect methods


    【解决方案1】:

    试试看

    <a href="<?php echo site_url('seller_controller/removeRow');?>" >CLICK TO REMOVE </a>
    

    或者你也可以试试

    <a href="<?php echo site_url().'seller_controller/removeRow';?>" >CLICK TO REMOVE </a>
    

    您继续使用base_url(),因为它不包含索引页面(可能是index.php),其中site_url()base_url()index url 结合使用。

    【讨论】:

      【解决方案2】:

      在脚本的请求处使用ob_start();

      【讨论】:

        【解决方案3】:

        发生这种情况,因为您的链接是相对的 - 即它被添加到当前 URI 减去最后一部分。把它想象成目录和文件——最后一部分(viewcart)是一个文件,其余部分是一个目录。相对链接的意思是“嘿,带我到这个文件 (removeRow),但从当前目录开始研究”。

        这意味着,如果您有 http://localhost/ignitershop/index.php/seller_controller/viewcart 并且您在那里访问内容为 &lt;a href="one/two/three"&gt;Link&lt;/a&gt; 的链接,它会将您发送到 http://localhost/ignitershop/index.php/seller_controller/one/two/three

        要修复它,请相应地使用 URL 帮助程序中的 base_url()site_url() 函数,这将为您完成这项工作。 Check out the documentation 了解更多信息。

        【讨论】:

          【解决方案4】:

          尝试通过使用 site_url() 或 base_url() 来使用绝对路径

          【讨论】:

            猜你喜欢
            • 2018-12-01
            • 1970-01-01
            • 1970-01-01
            • 2015-09-15
            • 2015-02-28
            • 2013-08-13
            • 1970-01-01
            • 2016-02-14
            • 2020-03-01
            相关资源
            最近更新 更多