![]() |
call static method from 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: call static method from model (/showthread.php?tid=10849) |
call static method from model - El Forum - 08-14-2008 [eluser]Unknown[/eluser] if i had understand the userguide if i want use a methode from model i should code like this. Code: $this->load->model('Commercial', '', TRUE); but if i want use a static method in order to not instanciate the object (that is the goal of a static methoc) ? apparently the load method use a singleton, it's better than anything, but if i want no instancitiation because of memory cost for example, should i write my controller like this: Code: require_once(myclass.php); By the way before write this post i have tried to set the static attribut, and it generate a warning. Normal ? it quite ugly no ? any answer or solution ? Thanks call static method from model - El Forum - 08-14-2008 [eluser]Sumon[/eluser] A bunch of code might be helpful for you. Whether i don't know using static variable are good practice or not. Anyway, in my project i use this static variable in some classes inside \application\libraries\ Here is an example class and how to use function. Code: class Custom_config extends Controller Code: // Inside method of a class however, i am not sure this is a good practice or not. So i also like to know about it. call static method from model - El Forum - 08-15-2008 [eluser]Unknown[/eluser] Thanks for your proposition, i was wondering if i would not use a librairy to use static method too. I 'm not sure that ur obliged to imply inheritance from controller if u don't use parent::Controller ... ![]() i will try your proposition, and compare with others thx call static method from model - El Forum - 08-15-2008 [eluser]Rick Jolly[/eluser] If you want to use a static method, either don't use the CI loader, or make a static class a helper. Unlike Models and Libraries, the CI loader doesn't instantiate helpers - because it doesn't expect them to be classes. All it does is include them. There is nothing stopping you from putting a class with static methods in the helpers directory though. |