title: How to access a variable in a PHP class that is set by another function? Codeigniter
body: <p>I have this code here in PHP using Codeigniter framework, I can't seem to get my head around class variables in this code seems completely different to C++.</p>
  
  <p>I was wondering how I can get a local variable in one class (function) method to another class method.</p>
  
  <p>But not passing them as variables as I have to use a redirect function instead which cannot take variables.</p>
  
  <p>The variable I want to have accessible is <strong>$record_id</strong> , i tried making it public etc does not like it.</p>
  
  <p>class Submit extends CI_Controller
  {</p>
  
  <pre><code>function send_data()
  {
          $record_id = $this-&gt;submit_model-&gt;create_record($completedstaffrows, $completedeventrows);
  
                          if ($record_id == FALSE)
                          {
                              echo "Failed to add to database";
                          }
  
                          //Submittal to database was successful
                          else
                          {
  
                              redirect('submit/success');
                          }
                          return;
                      }
  </code></pre>
  
  <p>This is the function that I want to have access the <strong>$record_id</strong>  </p>
  
  <pre><code>public function success()
  {
  
  $page['page'] = 'success';
  $page['record'] = $record_id;
  $this-&gt;load-&gt;view('template', $page );
  
  
  }
  </code></pre>
  
  <p><strong>Remember</strong> - I cannot pass this as a variable to the other function as I need to use a redirect so that my URL will not screw up. Thanks</p>
  
  <p>Cheers!</p>