![]() |
Loading model from variable? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Loading model from variable? (/showthread.php?tid=40701) |
Loading model from variable? - El Forum - 04-15-2011 [eluser]debow[/eluser] Is there a way to load a model from variable and call it throughout the controller. IE: controller/??.php Code: var $data = array( The reason being is I have controllers I can copy/paste and the only different is the table they are calling and their name so instead of having to change the the model name thats used many times in the controller I want to just change it in one location on each controller. Also want to call the model in this way as well. Code: $results = $this->$model->search($limit, $offset, $sort_by, $sort_order); Thanks Loading model from variable? - El Forum - 04-15-2011 [eluser]InsiteFX[/eluser] Code: $this->load->model($model) //This doesnt work...is there a way around it. InsiteFX Loading model from variable? - El Forum - 04-16-2011 [eluser]toopay[/eluser] Based by your ilustration... Code: var $data = array( Loading model from variable? - El Forum - 04-16-2011 [eluser]wiredesignz[/eluser] @InsiteFX and toopay: The array is obviously a class variable. Code: var $data = array( Loading model from variable? - El Forum - 04-16-2011 [eluser]ηυмвєяσηє[/eluser] btw, try "$model" instead of '$model'. Loading model from variable? - El Forum - 04-16-2011 [eluser]toopay[/eluser] @wiredesignz You're right about class var, i think both insiteFX and i didn't aware of that, especially for someone which reply this thread while drink a beer(thats me). It should be '$this->varname' not '$varname'. But he did clearly put this request too.. [quote author="debow" date="1302943535"] ... Also want to call the model in this way as well. Code: $results = $this->$model->search($limit, $offset, $sort_by, $sort_order); and then now, after clearing about class var, it seems you slightly slipped too, in your solution logics... [quote author="wiredesignz" date="1302959405"]@InsiteFX and toopay: The array is obviously a class variable. Code: var $data = array( based by above lines, then it will be running into this way... Code: $this->load->model($this->data['model']); @debow Code: //...some class var.... Loading model from variable? - El Forum - 04-16-2011 [eluser]InsiteFX[/eluser] Thanks wiredesignz, I had a wicked head ache last night! Should have gone to bed LOL! InsiteFX Loading model from variable? - El Forum - 04-16-2011 [eluser]toopay[/eluser] [quote author="InsiteFX" date="1302983974"]...Should have gone to bed LOL! InsiteFX[/quote] @InsiteFX, yep.. Your eyes seems tired... ![]() Loading model from variable? - El Forum - 04-16-2011 [eluser]debow[/eluser] Thanks toopay, that worked and its much eaiser to reuse my controllers from one to the other. |