Codeigniter : flashdata between redirect and loading view

10,355

Solution 1

Change in Controller :

$this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');

View is just as it is :

<?php echo $this->session->flashdata('flsh_msg'); ?>

Hope this helps you. Thanks!!

Solution 2

Try this.

function signup() { 
    if('user already exists') {
       $this->session->set_flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
          redirect('signup/signup/show_message'); 
    }
}

The setting function of flashdata is set_flashdata, not only flashdata.. only flashdata("flsh_msg") will get that string, but set_flashdata set it ;)

Share:
10,355
Mangesh Sathe
Author by

Mangesh Sathe

PHP, MySql developer with 8+years of experience. CodeIgniter, jQuery, javascript, HTML, CSS, Drupal 8, iOS and Android apps web service development, LAMP/WAMP.

Updated on June 04, 2022

Comments

  • Mangesh Sathe
    Mangesh Sathe almost 2 years

    In controller signup

        function signup() { 
         if('user already exists') {
         $this->session->flashdata('flsh_msg', 'You have already signed up using goole. you will be redirected to home page.');
        redirect('signup/signup/show_message'); 
         }
     }
    

    Show message in same controller, just to show view

     function show_message()
      {
          $this->load->view('header/header');
          $this->load->view('signup/signup_message');
          $this->load->view('footer/footer');
      }
    

    In View file :

    <div class="alert alert-success">
        <?php echo $this->session->flashdata('flsh_msg'); ?>
    </div>
    

    I am not able to show "You have already signed up using goole. you will be redirected to home page." message on view, I have tested keep_flashdata and set_flashdata.

    Is there any other method to do this? How can pass flash message between redirecting and then calling a view

  • Mangesh Sathe
    Mangesh Sathe about 9 years
    problem was flashdata. Changed to set_flashdata.. Thanks !!
  • Daniel Rossko Rosa
    Daniel Rossko Rosa about 9 years
    @MangeshSatheIND No problem, If you are satisfied with my answer, please click that arrow up and tag my answer as correct, thank you :)
  • Mangesh Sathe
    Mangesh Sathe about 9 years
    Daniel Rossko Rosa ...Vote up required 15 reputations. I have only 10
  • BDL
    BDL over 3 years
    Although this code might solve the problem, a good answer should explain what the code does and how it helps