Multiple method calls from library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Multiple method calls from library (/showthread.php?tid=66560) |
Multiple method calls from library - ManOfHonor - 11-04-2016 Hi there, I would like to know how can I call two methods from library in a loop? For example I have library called "Test" and I load it in my controller PHP Code: $this->load->library('test'); I have array with values, for example: PHP Code: $values = array(10, 20, 30, 40, 50); Now I have to loop through that array and call two methods from my library: PHP Code: foreach($values as $value) { My problem is that after the first call of these methods I can see returned value but after that I'm not getting any remaining values. How can I achieve that in CodeIgniter? RE: Multiple method calls from library - ramadhansutejo - 11-04-2016 can you show your library? RE: Multiple method calls from library - InsiteFX - 11-05-2016 Try making your $value array static. You will then need a clear method to reset it. RE: Multiple method calls from library - ManOfHonor - 11-05-2016 Thanks for yours reply. This is example of my library: PHP Code: defined('BASEPATH') OR exit('No direct script access allowed'); InsiteFX, do you mean something like this: PHP Code: defined('BASEPATH') OR exit('No direct script access allowed'); RE: Multiple method calls from library - InsiteFX - 11-06-2016 Yes, but like I said you will need to create a clear method to reset your value array. RE: Multiple method calls from library - ramadhansutejo - 11-06-2016 you mean like this? try to re-write tour library to : PHP Code: class Test RE: Multiple method calls from library - ManOfHonor - 11-08-2016 (11-06-2016, 06:44 PM)ramadhansutejo Wrote: you mean like this? Thanks for reply, I made a mistake and tried to extend CI_Controller in my library. Also I forgot that if I need to use CodeIgniter resources I can't extend it but I have to assign CodeIgniter object to variable by reference like you do. Regards, ManOfHonor |