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

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?

Could you give a scenario where it could be useful?

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.

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.

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

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