Error occured while call session value from a view file |
[eluser]Sumon[/eluser]
Hello all, I am trying to call a session variable from a view file. Its related to user login. Just like to show Welcome Guest Name or Login.... Here is my class inside system/application/libraries <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class login_operations { function IsLoggedIn() { if($this->session->userdata('UserId') != "") return TRUE; else return FALSE; } } ?> I call this IsLoggedIn() function from a view file as if( $this->login_operations->IsLoggedIn() ) Some Html View............... And I am getting this error PHP Error was encountered Severity: Notice Message: Undefined property: login_operations::$session Filename: libraries/login_operations.php Line Number: 7 Fatal error: Call to a member function userdata() on a non-object in D:\xampp\htdocs\OneHotNanny\system\application\libraries\login_operations.php on line 7 Please help me to resolve..
[eluser]Armchair Samurai[/eluser]
To call CI resources from your own functions, you need to to use get_instance(). Check up on the Creating Libraries section in the User Guide. Unless you've autoloaded the Session library, you'll also need to do so in your own library. For example. Code: class foo {
[eluser]Sumon[/eluser]
Thanks a lot... Infact my main question was: 1. Is there are any way to call a custom function of class located inside system/application/libraries? 2. Is it possible to call a controller from a view file? If yes then how? |
Welcome Guest, Not a member yet? Register Sign In |