• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing parameters to model constructor

#1
Sorry, I know this has been covered before.  Some of the questions regarding this are quite old, and I wondered why this functionality hasn't been made available as standard?

It would be really useful to be able to pass arguments to a model's constructor, along the lines of:

PHP Code:
$this->load->model('some_model'$args); 

Then in the model have:

PHP Code:
public function __construct($args) {


I know I could make my own initialization method and do:

PHP Code:
$this->load->model('some_model');
$this->some_model->init($args); 

However I have some arguments that are required for the whole model to work, and if I forget to call init() things will get somewhat messy.
Reply

#2
(08-19-2017, 04:08 AM)CINewb Wrote: Sorry, I know this has been covered before.  Some of the questions regarding this are quite old, and I wondered why this functionality hasn't been made available as standard?

It would be really useful to be able to pass arguments to a model's constructor, along the lines of:

PHP Code:
$this->load->model('some_model'$args); 

Then in the model have:

PHP Code:
public function __construct($args) {


I know I could make my own initialization method and do:

PHP Code:
$this->load->model('some_model');
$this->some_model->init($args); 

However I have some arguments that are required for the whole model to work, and if I forget to call init() things will get somewhat messy.

So force each method to check if the arguments have been initialized:

PHP Code:
if( $this->initialized // all is well 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.