Welcome Guest, Not a member yet? Register   Sign In
cant pass parameters from controller to a models constructor?
#1

[eluser]ajsie[/eluser]
cant you pass parameters from controller to a models constructor?

or do i have to pass it after i have loaded the model to another method?

$this->load->model('my_model');
$this->Contact_model('my name', 'my email');

so __construct() will ALWAYS be without parameters in CodeIgniter with other words?
#2

[eluser]adamp1[/eluser]
You could create an initialise method?

Code:
$this->load->model('my_model');
$this->my_model->initialise('my name', 'my email');
$this->my_model->......();

Then just have a bool check in each that it has a valid name/email. OR if you really wanted to pass constructor paramters. Override the Loader.php class so you can pass in config values like the load library method.
#3

[eluser]Zeeshan Rasool[/eluser]
[quote author="adamp1" date="1271072528"]You could create an initialise method?

Code:
$this->load->model('my_model');
$this->my_model->initialise('my name', 'my email');
$this->my_model->......();
[/quote]

Nice explanation !
You can also do this job with class variable of model.
If you want to use a model on bases of some param then create that models object and assign it a value as parameter. i-e In controller's any function assign
Code:
$this->yourModel->class_variable = 1
( or whatever you want to assign) and in the model declare
Code:
$this->class_variable
now you can pass parameter from any controller using this class variable of model and do your work on the basis of this class variable.

Regards,
Zeeshan
#4

[eluser]lezeroq[/eluser]
Maybe someone is still interested in this issue. Another solution.




Theme © iAndrew 2016 - Forum software by © MyBB