title: Codeigniter: preserving objects when linking from view
body: <p>I am new to both PHP and Codeigniter. </p>
  
  <p>I am loading a view from my controller. This view then has a form_open in it that directs to a function within that controller. Can I use variables previously set in my controller within that function?</p>
  
  <p>For example, the constructor of the controller loads a model. Then, another function in this controller calls <code>$this-&gt;model-&gt;someFunction($id)</code> and sets the <code>$id</code> variable of my model to <code>$id</code>. Later, after a link is clicked in my view, it goes to a different function in the controller which then calls <code>$this-model-&gt;printID()</code>. This fails because in my model, <code>$id</code> is not set.</p>
  
  <p>How can I achieve that a link goes to a function that accesses the same object (or model) that I modified earlier? That is, the final echo of $ID returns a blank string - the <code>$ID</code> is not set as I would have expected it to be.</p>
  
  <p>Thanks in advance for the help. </p>
  
  <p>My controller:</p>
  
  <pre><code>class Studio extends CI_Controller { 
  
  public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;model('studio_model','',TRUE);
  }
  
  function view($id)
  {
      $this-&gt;studio_model-&gt;setID($id);
      $this-&gt;load-&gt;view('studio_view');
  }
  
  function signup(){                  
      $ID = $this-&gt;input-&gt;post('ID');
      $this-&gt;studio_model-&gt;signup($ID);
  }
  }
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>Class studio_model extends CI_Model{
  
  public $ID;
  
  function setID($id) {
      $this-&gt;ID = $id;
  }
  
  function signup($ID){
      echo $this-&gt;ID;
      echo $classID;
  }
  </code></pre>