custom library with parameters : problem |
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.
You can do it like this:
PHP Code: private $items; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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
That's because CI controllers have access to the CI Global Super Objects, views do not.
PHP Code: private $CI; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
$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 |
Welcome Guest, Not a member yet? Register Sign In |