Hi, i'm in the controller of a model and in this controller I want to load the information of another model passing it the specific id in the db.
How can I do this?
Make me an example please with a model name
Hi, i'm in the controller of a model and in this controller I want to load the information of another model passing it the specific id in the db.
How can I do this?
Make me an example please with a model name
in the ModelAController you can call
ModelB::model()->findByPk($id) // OR any method of ModelB
Ah ok so I can't call a method of ModelBController.php ?
Couse the loadModelB($id=null) is in ModelBController.php
So I have to copy it in the ModelBController or just use the part of code tha I need, isn't it?
Ok maybe I'm saying a stupid thing…
But I think that I can use $modelBobj = new ModelB($_GET['id']);
Like in every OOP language as costructor… Am I right?
You can still call a method of a different controller (as long as you include class file first). However, in this case, it is better to abstract the shared code out and save them in a separate class (or in the model class).