![]() |
Extend CI model to allow params to be passed to the constructor? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Extend CI model to allow params to be passed to the constructor? (/showthread.php?tid=77533) |
Extend CI model to allow params to be passed to the constructor? - mlurie - 09-12-2020 Is it possible to extend CodeIgniter's model to allow parameters to be passed to the constructor? I have four models that are almost identical. If there were a way to pass the table name and the allowed fields array to the model via the constructor, I could eliminate a bunch of code. RE: Extend CI model to allow params to be passed to the constructor? - Omar Crespo - 09-12-2020 Are you uzing CI4 or still CI3?? RE: Extend CI model to allow params to be passed to the constructor? - mlurie - 09-12-2020 I am using CI4. RE: Extend CI model to allow params to be passed to the constructor? - InsiteFX - 09-13-2020 That would require you to update the system/model and that is not recommended you should never change a system file. You could extended say the BaseModel, setup your Constructor and then extend all your models form the BaseModel. In the BaseModel do not use the parent__construct() only in the model that you extend from the BaseModel. BaseModel extends Model All your Models extend BaseModel |