Mysterio4
Mysterio4

Reputation: 331

page redirect issue codeigniter

I am unable to redirect to page using the redirect() in codeigniter. Also the same problem if I try to use location.href within view. It just redirects me to the page without the css and js includes

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');
            }
        }
    }

PASSAGE CONTROLLER

<?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);
    }
}

Please help I dont know whats going wrong. I can access http://localhost/tsb/passage/ directly from address bar but none of these will work properly location.href="passage/";or redirect(base_url() . 'passage/', 'refresh'); This is how it displays

enter image description here

Upvotes: 0

Views: 1937

Answers (1)

Hikmat Sijapati
Hikmat Sijapati

Reputation: 6994

At controller try this code. First load url helper then try..

The redirect statement in code igniter sends the user to the specified web page using a redirect header statement.This statement resides in the URL helper which is loaded in the following way:

 $this->load->helper('url'); //loads url helper

Controller:

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');
            }
        }
    }

Upvotes: 1

Related Questions