页面重定向问题codeigniter

时间:2017-01-09 15:55:48

标签: php .htaccess codeigniter

我无法使用codeigniter中的redirect()重定向到网页。如果我尝试在视图中使用location.href,也会出现同样的问题。它只是将我重定向到没有css和js包含的页面

mY CONFIG

$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>

BOOK CONTROLLER

 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/";redirect(base_url() . 'passage/', 'refresh');这就是它的显示方式

enter image description here

1 个答案:

答案 0 :(得分:1)

在控制器上尝试此代码。首先加载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');
            }
        }
    }
相关问题