Welcome Guest, Not a member yet? Register   Sign In
problem with session in template
#7

(This post was last modified: 05-17-2015, 03:24 AM by StratoKyke.)

I created MY_Controller in application/core/ and this is the code:

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
MY_Controller extends CI_Controller {

 
       public function __construct() {
 
               parent::__construct();
 
       }

 
       public function index() {
 
               $session_data $this->session->userdata('logged_in');
 
               $data['username'] = $session_data['login'];
 
               $this->smarty->assign('user_log'$session_data);
 
       }



In the all other controller I edit in this way:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
NameClass extends MY_Controller 

But when I try to access in the page I found this error:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: user_log

Filename: compiled/c3a9b50f1375d1dde5af34b18cf8ecc0df629901.file.rightSide.tpl.php

Line Number: 33

Backtrace:
Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: compiled/c3a9b50f1375d1dde5af34b18cf8ecc0df629901.file.rightSide.tpl.php

Line Number: 33

Huh How should I do?

Sorry but it is the first time that I attempt to well with CI


EDIT: If I move 
Code:
$session_data = $this->session->userdata('logged_in');
               $data['username'] = $session_data['login'];
               $this->smarty->assign('user_log', $session_data);

In the __construct() session data makes them see me but this is the error:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: username

Filename: compiled/c3a9b50f1375d1dde5af34b18cf8ecc0df629901.file.rightSide.tpl.php

Line Number: 35
Reply


Messages In This Thread
problem with session in template - by StratoKyke - 05-14-2015, 02:35 AM
RE: problem with session in template - by CroNiX - 05-16-2015, 03:56 PM
RE: problem with session in template - by StratoKyke - 05-17-2015, 03:18 AM
RE: problem with session in template - by CroNiX - 05-17-2015, 09:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB