![]() |
how to pass argument to model constructor while loading a model - 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: how to pass argument to model constructor while loading a model (/showthread.php?tid=19079) |
how to pass argument to model constructor while loading a model - El Forum - 05-27-2009 [eluser]pankaj[/eluser] how to pass argument to model constructor while loading a model normally we follow Code: $this->load-model('user'); how to pass argument to model constructor while loading a model - El Forum - 05-27-2009 [eluser]Evil Wizard[/eluser] A library can accept __constructor parameters but the model doesn't see to. The alternative is to create an initialise() method that will accept your construct params. Code: class user_model extends model { Code: $this->load->model('user_model'); how to pass argument to model constructor while loading a model - El Forum - 05-27-2009 [eluser]TheFuzzy0ne[/eluser] I second that. It's always a good idea to have an initialisation method which you can call from the constructor if need be, although in your case, it's pretty pointless if you're loading the model via CodeIgniter's loader. I'd like to point out, however, that it's probably wiser to stick to the US spelling, so your method should be called initialize(). how to pass argument to model constructor while loading a model - El Forum - 12-15-2010 [eluser]lezeroq[/eluser] Maybe someone is still interested in this issue. You can modify system library system/libraries/Loader.php, replace Code: function model($model, $name = '', $db_conn = FALSE) Code: function model($model, $name = '', $db_conn = FALSE) Code: class ExampleModel extends Model { Code: $this->load->model('ExampleModel', '', FALSE, $param1, $param2); ![]() how to pass argument to model constructor while loading a model - El Forum - 02-28-2011 [eluser]Unknown[/eluser] I think this is an excellent extension - maybe improved only by making the 4th param an optional array, and then handling namespace variables like passage in views. Is this approach headed for core? how to pass argument to model constructor while loading a model - El Forum - 05-27-2011 [eluser]MathBoon[/eluser] This would really be a nice extension, i vote for making this another core element ![]() how to pass argument to model constructor while loading a model - El Forum - 05-20-2012 [eluser]Andreas Bergström[/eluser] This helped me a lot, I second putting this in the core. how to pass argument to model constructor while loading a model - El Forum - 01-06-2013 [eluser]Unknown[/eluser] Love it, has it been added yet? |