CodeIgniter Forums
Where should I put this function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Where should I put this function? (/showthread.php?tid=57031)



Where should I put this function? - El Forum - 02-08-2013

[eluser]gregormck[/eluser]
I have a function within a separate model that creates an array of data based on GET values like so:

Code:
$data_array = $this->some_model->some_function($this->input->get(null, true));

Within another model (e.g. "another_model") $data_array is used across many functions / methods. Rather than call "some_model->some_function" each time I access the other functions from within "another_model", I want to set $data_array as a variable that can be used across all functions within "another_model". Is this the correct way to do it:

Code:
class Another_model extends CI_model
{

  private $data_array = array();

  function __construct()
  {
    parent::__construct();
    $this->data_array = $this->some_model->some_function($this->input->get(null, true));
  }
        
  public function_one()
  {
    // uses $this->data_array
  }

  private function_two()
  {
    // uses $this->data_array
  }

}



Where should I put this function? - El Forum - 02-08-2013

[eluser]Aken[/eluser]
Yup that's fine.


Where should I put this function? - El Forum - 02-11-2013

[eluser]gregormck[/eluser]
Thanks!