title: codeigniter pass variable from controller to model
body: <p>simple issue I presume.</p>
  
  <p>My controller is getting the if to display from the url using <code>$this-&gt;uri-&gt;segment(3)</code>. This will always be a single value. I am putting this in an array to pass to the model with:</p>
  
  <pre><code>$customerid = array(
     'id' =&gt; $this-&gt;uri-&gt;segment(3)
  );
  </code></pre>
  
  <p><strong>The controller syntax is below:</strong></p>
  
  <pre><code>function confirm_delete_customer()
  {
              $data['title']="Confirm Customer Deletion";
  
              $customerid=array(
                  'id'=&gt;$this-&gt;uri-&gt;segment(3)
                  );
  
              //query model to get data results for form
              $data=array();
  
              if($query=$this-&gt;model_master_data-&gt;get_customer_records_to_delete()){
                  $data['records']=$query;
  
  
              $this-&gt;load-&gt;view("master_data/view_master_data_header",$data);
              $this-&gt;load-&gt;view("master_data/view_master_data_nav");
              $this-&gt;load-&gt;view("master_data/view_content_master_data_confirm_customer_deletion",$data);
              $this-&gt;load-&gt;view("master_data/view_master_data_footer");
  
  
  
  }
  </code></pre>
  
  <p>I am then trying to access this array value and pass it to my model to process. If I hard code the array into the model it works as per below syntax:</p>
  
  <p><strong>Model - Manual Syntax is:</strong></p>
  
  <pre><code>function get_customer_records_to_delete()
  {
      $query = $this-&gt;db-&gt;get_where('customers', array('id'=&gt;43));
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>if I try replace this with the array from my controller it fails with error:
  <code>Undefined variable: customerid</code></p>
  
  <p><strong>idea of model that I want to get working:</strong></p>
  
  <pre><code>function get_customer_records_to_delete()
  {
      $query = $this-&gt;db-&gt;get_where('customers', $customerid);
      return $query-&gt;result();
  }
  </code></pre>
  
  <p>I have a feeling it is something small. however is this the best way to get a single record from the database in order to output to a view?</p>
  
  <p>Thanks in advance for the assistance.</p>