2017-01-09 119 views
0

我无法重定向到在codeigniter中使用redirect()的页面。如果我尝试在视图内使用location.href也是同样的问题。它只是重定向我的网页没有CSS和JS包括页面重定向问题codeigniter

我的配置

$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控制器

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

在控制器试试这个代码。首先负载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'); 
      } 
     } 
    }