dqyym3667 2015-11-13 04:48
浏览 57
已采纳

CodeIgniter 3重定向功能不起作用

I'm in the process of re-coding and updating my CMS I've got working in CI2, to CI3, and for the life of me I cannot get my redirect function to work for me on CI3.

Outside of redesigning my Models, my code thus far is is identical to my CI2 code. Originally I suspected my layout hook was the culprit, but I've completely disabled him and I'm still not getting anywhere.

public function login ()
{
    //var_dump(logged_in());
    //if (logged_in())
        redirect('/user/');
}

Above is the entirety of my login function at the moment, from my User controller. I've removed all the other code in an effort to pinpoint this problem. I've even commented out the if statement thinking that it might even by the culprit. nope.

My logged_in() function returns TRUE, or FALSE, depending on certain things set in my user sessions. That appears to be functioning fine. As far as I can tell, my configs settings looks good. I have the URI helper autoloaded, and other URI helper methods function properly.

Now for the strange part. When I visit /user/login, not only does my page not redirect, if I un-comment the var_dump() before the redirect (which returns true), and re-comment it, the page doesn't update, and I have bool(true) on my screen regardless. If the var_dump is commented and I open a new tab to users/login it simply doesn't load anything, and it just hangs out as a new tab.

Edit: I've forgotten to mention that when I use the 'refresh' flag (redirect('/user/', 'refresh');), that simply takes me to an about:blank page.

Edit#2: I've copied the CI3 files into a new "project", and even those wont redirect using the built in Welcome_Message view/controller combo.

  • 写回答

3条回答 默认 最新

  • doutangguali32556 2015-11-17 07:11
    关注

    Through a lot of trial and error, I've since discovered my problem. When I performed var_dump(base_url) I found out that I was $_SERVER['SERVER_ADDR'], and since I was working locally, that is ::1. What I learned was base_url wasnt working like it was in CI2. Sadpanda.

    Base_url config variable was incorrectly set. In config/config.php my base_url was set using a single quote. Allowing CI3 to guess the protocol, it would default to $_SERVER['SERVER_ADDR'], which would return ::1 since I am working locally. Furthermore, when I set the variable to 'http://localhost/supersecretname', using single quotes the exact same problem popped up as when it was using the auto SERVER_ADDR

    By some miracle of sleep deprivation, I was trying many different values here, and at some point I switched from single, to double quotes.

    And thus, a solution was found.

    $config['base_url'] = "http://localhost/supersecretname";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计