0
 class Welcome extends CI_Controller{
      function checker(){
          if (!$_SESSION['bla']) {
             $data['include'] = "REGISTER"; //first result
          }else{
            $data['include'] = "template";
          }
             $this->load->view('template', $data);  //second result
       }
   //STOP HERE IF RESULT IS FIRST 
       function index(){
          $data['include'] = "index";
         $this->load->view('template', $data);
       }
    }

I want if in my page dont have session all user redirect to 'REGISTER' page, all classess, all functions to redirect in REGISTER page if dont have session. BUt if user has session just can use site normal. HOw to do this ?

I dont want in every class to put this check ... THanks

1 Answers1

1

Create a controller MY_Controller in application/core/MY_Controller.php and extend the CI_Controller like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller{

    function __construct() {
        parent::__construct();

        // do the checking here...
        // if condition fails redirect...
}

}

Extend this MY_Controller class in your every controller instead of CI_Controller so in every request the checking would take place at first. For example:

class User extends MY_Controller {
    // ...
}
The Alpha
  • 143,660
  • 29
  • 287
  • 307
  • I am using $this->load->view('template', $data); to redirect my page (with VIEW i show my error page) BUt when i load another class this class runing after this check and i load 404 and another page together. HOw to do when i have session users cant do anything in site but when users haave session site work normal ? Just want when i have session to use site normal can use class and function but when i dont have session all site block and give me 404 – user3576620 Apr 27 '14 at 07:10
  • I want to redirect when i dont have session read above. When i have session i want to use site normal but when i dont have session always redirect me to 404.php. – user3576620 Apr 27 '14 at 07:17
  • WereWorf thats result for my question just i want to know how to load->view page not redirect, because i am using parameters $data['include'] = "no-like"; $this->load->view('template', $data); parameters like a include and title. Your check work perfect, but when i load-view my 404 and try to open another class thats work.. another class runinng bellow from 404 – user3576620 Apr 27 '14 at 07:29
  • I'm completely confused what you are talking, do you want to redirect when session is not there or what ? – The Alpha Apr 27 '14 at 07:30
  • I have check above i create check and if i have session view->load 404 page and if i dont have session i load index pageBut after this code i have more functions like a AddNews ViewNews and when this check give me 404 page i again can using another functions and classes. How to do when i load->view 404 to cant read another code and classses only when i have session to can read another functions – user3576620 Apr 27 '14 at 07:38
  • You need to redirect not `load->view()`, just redirect to another controller which loads the `404` view. – The Alpha Apr 27 '14 at 07:41