• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flashdatas and Redirection

#1
[eluser]Diantre[/eluser]
Hi,

First of all, i'd like to apologize for my poor english, I am actually french...nobody's perfect ;-)

I have some problems with Flashdatas and Redirection.

I am using a personal "super controller" (MY_Controller) that takes care about login. It detects if someone tries to log in, check the informations etc. If everything goes normally, the method redirects to the main page. Otherwise it displays the connection page (with errors).
I want to display a confirmation message on the main page after the user logged in. So I set a flashdata message.
The problem is that I actually can't take the message back in my main page controller after the redirection and i don't understand why.
Flash datas are supposed to be "available for the next server request, and are then automatically cleared".
In my case, the next server request isn't the one which asks the redirected page ? I even tried with the method keep_session but it doesn't seem to be the key.

Some simple code to illustrate my problem:
The "super controller" class...
Code:
class MY_Controller extends Controller {

function MY_Controller() {
    parent::Controller();
    // loading of some libraries like database, session, etc.

    $this->login_management();
}

function login_management() {
   //form checking

   // if everything is okay
   $this->session->set_flashdata('login','message: login ok !');
   redirect('main_controller');

  // otherwise the controller keep executing the current page which is the connection page
}
}

Then a "classic" controller...
Code:
class Main_controller extends MY_Controller {

function Main_Controller() {
    parent::MY_Controller();
}

function index(){
$this->load->view('main_view');
}

And finally the main_view.php
Code:
<?php var_dump($this->session->flashdata('login'); ?>

I'm thinking about writing some methods that allows me to use classic session as flash session to do this but I am sure there is a solution I don't know.

Pending an answer, thank you in advance.

Diantre.

#2
[eluser]Diantre[/eluser]
I found the problem. I guess I should read my code 10 more times before asking dumb questions.

I did a redirection to main_controller but in reality, my main_controller's index method was:
Code:
redirect('main_controller/display');

I've changed it to:
Code:
$this->display();

Well, that was obvious. Sorry for disturbing the peaceful community Smile

Diantre.

#3
[eluser]richfearless[/eluser]
Hi Diantre, welcome to CodeIgniter forums..

I am glad you solved your problem.
Their is no need to apologize!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.