![]() |
Use functions in extended models in there DB - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Use functions in extended models in there DB (/showthread.php?tid=81362) |
Use functions in extended models in there DB - sprhld - 02-19-2022 Hello! I'm using extended Models where I have function which are the same request in all extending models. Lets say, a function "getBySlug()" is used in a CommentsModel and in PostModel or so because both have the field "slug". This "BaseModel" does not represent a table in my database. But now I have this point, where the "BaseModel" does represent a table and I would use functions in this model. Thats what I have: First, there is a "pathModel" which represents my list of paths to every object (which I call subject, just in case you find somewhere in my examble the word subject *g). In this DB I have 2 columns, "id" and "path". Every n/ is the ID of an object. Every object can placed on every level in a path. Code: id | path Then I have a object DB which has also only three field, "id", "subject_id" and "subject_type". Code: id | subject_id | subject_type On the next level, I have for every type an own table with specific columns, but we don't need it here. The objectModel extends pathModel. In path model I have a function to find the IDs which have no children, which must be the first objects of a navigator. I can't call it because called with $this->firstIds() searches in the table of objects - what I understand. The quest is, is there a way to do so? The structure basically represents a JOIN (maybe not path to object but object to types later on). What I want to do is something like this in pathModel: PHP Code: function firstIds() And call this in objects to work with the return. Right now, I call the extended model as an new model and I work with this object. But It feels not right :-) There are any other best cases? I hope you understand what where it should goes to :-) |