[英]page redirect issue codeigniter
我无法使用codeigniter中的redirect()
重定向到页面。 如果我尝试在视图中使用location.href
,也会遇到同样的问题。 它只是将我重定向到没有CSS和js的页面
配置文件
$config['base_url'] = 'http://localhost/tsb/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI'; //I have switched the 3 protocols too
HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
预订控制器
public function psg_sel()
{
$book_name = $this->input->post('book_name');
$book_id = $this->cj_model->get_book_id($book_name);
$ch_id = $this->input->post('chapter_id');
$cj_mask = $this->input->post('cj_mask');
if($cj_mask == ''){
$psg_sel = $this->cj_model->psg_sel($book_id, $ch_id);
if($psg_sel === true){
redirect(base_url() . 'passage/', 'refresh');
}
}
}
通道控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Passage extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
}
public function index()
{
$data['page_name'] = 'passage';
$this->load->view('pages/index', $data);
}
}
请帮助我不知道出了什么问题。 我可以直接从地址栏中访问http://localhost/tsb/passage/
,但是这些都不能在location.href="passage/";
正常运行location.href="passage/";
或redirect(base_url() . 'passage/', 'refresh');
它是这样显示的
在控制器上尝试此代码。 首先加载url
帮助程序,然后尝试。
代码点火器中的redirect语句使用重定向标头语句将用户发送到指定的网页。该语句驻留在URL帮助器中,该URL帮助器通过以下方式加载:
$this->load->helper('url'); //loads url helper
控制器:
public function psg_sel()
{
$this->load->helper('url'); //loads url helper
$book_name = $this->input->post('book_name');
$book_id = $this->cj_model->get_book_id($book_name);
$ch_id = $this->input->post('chapter_id');
$cj_mask = $this->input->post('cj_mask');
if($cj_mask == ''){
$psg_sel = $this->cj_model->psg_sel($book_id, $ch_id);
if($psg_sel === true){
redirect(base_url('passage'), 'refresh');
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.