在 Codeigniter 中重定向
我有一个分页显示,在每个页面调用中我将当前 URI 字符串设置到会话中(在我的控制器中)。
$current = $this->uri->uri_string();
$this->session->set_userdata('return_to', $current);
从视图中,用户可以单击链接转到其他地方(编辑表单),提交后(并且表单验证正确)我想返回到分页结果的正确页面。
if($this->form_validation->run('edit') == TRUE )
{
$back_to = NULL;
$back_to = '/'.$this->session->userdata('return_to');
....
redirect($back_to);
}
似乎有时在 Firefox 中工作,但在 Chrome 中死机,重定向到 favicon.ico
任何和所有帮助都表示赞赏
更新: 我的问题不是由于相对/绝对地址造成的,由于第二个控制器中的某些奇怪原因,重定向的目标是 favicon.ico,而不是会话中存储的内容。
I have a paginated display in which on each page call I set the current URI string into a session (in my controller).
$current = $this->uri->uri_string();
$this->session->set_userdata('return_to', $current);
From the view the user can click a link to go somewhere else (an edit form), which when submitted (and form validation is correct) I want to return to the correct page of the paginated results.
if($this->form_validation->run('edit') == TRUE )
{
$back_to = NULL;
$back_to = '/'.$this->session->userdata('return_to');
....
redirect($back_to);
}
Seems to work sometimes in Firefox but dies in Chrome, redirect to favicon.ico
Any and all help appreciated
UPDATE:
My problem isn't due to relative/absolute addresses, for some weird reason in the second controller the redirect aims to favicon.ico, not what was stored in the session.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要分配变量,
redirect()
使用完整的 url 和分段的 url(很像 site_url(),这正是uri_string()
返回的内容)因此,如果这不起作用,则可能是您的会话未设置或已过期。此外,请考虑 CI 的会话是 cookie ,因此浏览器可以在其中发挥作用。
Don't need to assign a variable,
redirect()
uses both a full url and a segmented url (much like site_url(), which is exactly what is returned byuri_string()
.So if this doesn't work, it's likely your session is not set or expired. Also, consider that CI's sessions are cookies , so a browser can has its role in here.
我会使用绝对 URL,而不是相对 URL。
尝试一下
正如 Stealthyninja 指出的那样,最好使用 CodeIgniter 的 site_url() 或 base_url() 而不是对其进行硬编码。在 config.php 中设置 site_url() (我相信)
I would use an absolute URL and not a relative one.
Try this
As stealthyninja pointed out it's probably better to use CodeIgniter's site_url() or base_url() instead of hard coding it. Set the site_url() in the config.php (i believe)