Welcome Guest, Not a member yet? Register   Sign In
Passing values to model constructor
#1

[eluser]MABUS[/eluser]
Hi guys,

I'm wondering how to be able to pass a variable or values to a model's constructor. Is that possible in ci? from the manual, when you call on to a model, the second attribute paramter that you pass to the function is the name that you pass when you want to use a different name for that particular model.

So is passing an argument to a model's constructor possible?
#2

[eluser]xwero[/eluser]
Could you give a scenario where it could be useful?
#3

[eluser]MABUS[/eluser]
Lets say I am loading a model, which extends to an abstract class. Now I'd like to pass something to the constructor, which is to be used only by the child class. Lets say the Parent class, which is abstract has more then one child. Lets say each chid is corresponding to a database entitiy, and each of those children has "profile" id in it, but of course they are of different types.

bottom line, what if I'd like to be able to pass something in a controller's constructor.
#4

[eluser]xwero[/eluser]
It isn't possible with the current CI code.

But i think what you are after can be solved with a set method in the abstract class.
#5

[eluser]wiredesignz[/eluser]
You could set a Controller class variable that the Model checks for and uses in its constructor. However while CI assigns all it's class variables to a Model, they may not be availabe until after the constructor is run. You'd need to check this.




Theme © iAndrew 2016 - Forum software by © MyBB