![]() |
How i can use model in other 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 i can use model in other model? (/showthread.php?tid=4994) |
How i can use model in other model? - El Forum - 12-30-2007 [eluser]Pitrsonek[/eluser] Hi, please how i can use model in other model? I cant finde it in user guide. Ther you can see, i want use model comments but it doesnt work. THX Code: <?php How i can use model in other model? - El Forum - 12-30-2007 [eluser]Phil Sturgeon[/eluser] Sadly models are not loaded in the model class, so using $this-> doesnt give you any access to them. You need to grab the instance using get_instance() then use THAT new object pointer to access your models. Code: <?php How i can use model in other model? - El Forum - 12-30-2007 [eluser]Craig A Rodway[/eluser] Load the CI instance into a variable, and load/access other models through it, like this: Code: <?php How i can use model in other model? - El Forum - 12-30-2007 [eluser]Phil Sturgeon[/eluser] Sometimes PHP4 has trouble with the instance when loaded that way. Its better to assign it each time you need it, as creating a pointer takes barely any time at all, so there is no real benefit to loading it upon contruction. If you are doing it that way, dont forge to set the property. :p Code: var $CI; How i can use model in other model? - El Forum - 12-30-2007 [eluser]Craig A Rodway[/eluser] Ah yes, you're right.. it seems PHP4 requires them to be declared first. I still find it easier to make it available to the whole model in the constructor - I could use it once or I could use it a dozen times and it keeps each function 2 lines shorter ![]() How i can use model in other model? - El Forum - 01-05-2008 [eluser]jurosik[/eluser] Craig, could you write code of what you say, please? "to make it available to the whole model in the constructor" It will help me a lot! I'm tryin' to load more models in one model, but it doesn't work. Thank you very much How i can use model in other model? - El Forum - 01-05-2008 [eluser]Phil Sturgeon[/eluser] He already did :p Code: <?php How i can use model in other model? - El Forum - 01-05-2008 [eluser]jurosik[/eluser] Maybe I should write more... I had one big model with all functions, but now i need to make this model more comprendious, so i allocate my functions into tematic models. but functions have calls between models. I need to load model once, and then just call them anywhere in model... Code: model1 i have tried this: Code: class Data_model extends Model { But when i load file Data_model in Main_model (here is function 1 which i am calling from Data_model) it doesn't work Code: class Main_model extends Model { mybe it's very complicated to explain... How i can use model in other model? - El Forum - 01-05-2008 [eluser]Craig A Rodway[/eluser] What errors are you getting and what isn't working? How i can use model in other model? - El Forum - 01-05-2008 [eluser]jurosik[/eluser] Browser won't open the page: "the server unexpectedly dropped the connection" it happens after i load model in another model which i am calling function In controller Code: class Jobs extends Controller { In Data_model Code: class Data_model extends Model { Main_model Code: class Main_model extends Model { |