custom library with parameters : problem - 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: custom library with parameters : problem (/showthread.php?tid=63556) |
custom library with parameters : problem - casa - 11-13-2015 hello, i want to use custom libray with parameters on its constuctor. I've a fatal error. My libray class (in folder library) PHP Code: // class file named Example.php My test view page PHP Code: //view file : my_view.php Thank you. RE: custom library with parameters : problem - InsiteFX - 11-13-2015 You can do it like this: PHP Code: private $items; RE: custom library with parameters : problem - casa - 11-13-2015 Thanks, but it's not working too because i note that : - if you load library in the view page, there is error - if you load library in the controller and then use it in the view, that's working !! PHP Code: // controller file PHP Code: // view file : my_view.php RE: custom library with parameters : problem - InsiteFX - 11-13-2015 That's because CI controllers have access to the CI Global Super Objects, views do not. PHP Code: private $CI; RE: custom library with parameters : problem - Martin7483 - 11-13-2015 $this will only contain objects that are loaded before the view is loaded. If you want to load classes in a view you must do it like this: PHP Code: $ci =& get_instance(); This is one of the reasons using $this in views should be avoided. Pass everything you need in your view via the data argument when loading a view RE: custom library with parameters : problem - casa - 11-13-2015 @Martin and InsiteFx Thank you for your help and explaination |