CodeIgniter Forums

Full Version: Why session do not !!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hi !!!

- code Structure is following:
---> Master page: main.php (extends Controller)
---> Controllers: controllers/[folder_name]/[controller_name].php (extends Controller)

---> Note: [...]: can be change

- Idea for these do !!!: all request from client will be access directly to Master page (main.php). Master page will be choice controller and method of it (I write MLoader.php class for load controllers).

- Problem: inside Master page i can call $this->session->userdata('session_name');. It do well. But i can not call $this->session->userdata('session_name'); insite Controllers.

Error:
Fatal error: Call to a member function set_userdata() on a non-object in C:\xampp\htdocs\revnicts\system\admin\controllers\account\account.php on line 17

This is account controller code:
<?php
class Account extends Controller {

--------function Account() {
----------------parent::Controller();
--------}

--------function index() {
----------------return '';
--------}

--------function login() {
----------------$session_data = array( 'admin_id' => 1,
----------------------------------------'logged_in' => TRUE
----------------------------------------);

----------------$this->session->set_userdata($session_data);

----------------return 'login box';
--------}
}
?>

Please tell me the way fix this problem

Thanks,

El Forum

[eluser]Unknown[/eluser]
Can you send display the master.php page?

Fatal error: Call to a member function set_userdata() on a non-object in C:\xampp\htdocs\revnicts\system\admin\controllers\account\account.php on line 17

This error implies that you have not created the object correctly.

A short potential fix is

$obj=& get_instance();
$obj->session->set_userdata($session_data);

But you shouldn't rely on this. As clearly something is a miss.

I too am having my own fun and games with session setting.
If you are testing on a localhost machine. Your cookie might not even be setting at all if you set the "cookie_domain" to 'localhost'

A bug persay in php or not, but if it is localhost, you actually need the value to equal false.

Please refer to my little article I put up, with demo code to explain what im talking about further.

http://www.freshteapot.net/inthepantry/H...h-php.html

El Forum

[eluser]Michael Wales[/eluser]
My first guess is - are you loading the Session library?

Also, please wrap you code in the appropriate tags when posting - it makes it a bit easier to read.