How on earth do you use a custom function in this???!!!! [SOLVED] |
[eluser]Emkay[/eluser]
All I want to do is store a function in a library and then call it whenever I want. Seems simple enough, but CI is making it a nightmare trying to get it to work. This is what I have done. - Created a new file called "Standard.php" in the libraries folder - Created a class opener inside this file, also called "Standard" - Added my custom function, called "authorize" - Configured the autoload.php file in the config folder to auto load this library - Tried to call the function from one of my controllers using: Code: $this->standard->authorize(2); Yet I get this error: Code: Fatal error: Call to a member function userdata() on a non-object in C:\wamp\www\site\libraries\Standard.php on line 15 What on earth am I doing wrong? How can such a simple procedure not work?! I'm tearing my hair out over this! Help me please! This is my Standard.php library file. Code: <?php
[eluser]Andreas Karlsson[/eluser]
You need to load the session library. $this->session is not defined so you need to load it before you do $this->session->userdata(); http://ellislab.com/codeigniter/user-gui...oader.html
[eluser]Aken[/eluser]
You also need to create a variable to use the CodeIgniter super object in your class. When using Libraries, $this will always refer to the library class, NOT the CI super object (in your case, $this will be the Standard class). This is what I would recommend doing: Step 1) Add the Session library to your autoload (you want sessions on every page, so might as well load it by default). Step 2) Change your library code to the following: Code: <?php
|
Welcome Guest, Not a member yet? Register Sign In |