我正在使用 CodeIgniter。有人可以知道这件事吗? 我正在尝试使用以下代码重定向页面:
window.location.href = "<?php $this->output->set_header(refresh:1; url=login); ?>";
但是它不起作用。
这是我的 Controller 中的代码。
public function view_login(){
$this->load->view('login');
}
这是我的 route 的代码。
$route['view_login'] = 'Controller/view_login';
最佳答案
启用 URL Helper 并在 config/config.php 上设置基本 url 在您的路线中只需使用:
$route['view_login'] = 'view_login';
对于重定向网址使用:
<script>
window.location.href = "<?php base_url().'/view_login' ?>";
</script>
如果你不使用 .htaccess 来删除/index.php 使用这个:
<script>
window.location.href = "<?php base_url().'index.php/view_login' ?>";
</script>
Note : for more information about URL Helper Codeigniter please visit documentation : https://www.codeigniter.com/user_guide/helpers/url_helper.html
关于javascript - 如何重定向页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55087935/