Hi,
I am using Sessions in Cakephp . I am having 3 controllers .In the User controller while logged in , i have wrote the User id in the Session variable .
But when i try to read it in the other controller i am getting the value of the Session variable.WHy so???
Edit :
In my users controller
i am writing the User id of the person who have logged in as
function login()
{
$this->Session->write('userId',$this->User->loginUser($this->data));
$this->User->data=$this->data;
if (!$this->User->validates())
{
$this->Flash('Please enter valid inputs','/main' );
return;
}
if($this->Session->read('userId')>0){
$this->Session->setFlash('Login Successful');
$this->redirect('/main/home');
break;
}
else{
$this->flash('Username and password do not match.','/main');
}
}
And in my forms controller i am trying to read the session variable user id like..,
<?php
class FormsController extends AppController
{
var $name = 'Forms';
var $helpers=array('Html','Ajax','Javascript','Form');
var $components = array( 'RequestHandler','Autocomplete');
var $uses=array('Form','User','Attribute','Result','Invite','Share','Choice');
function index() {}
function design()
{
$userId=$this->Session->read('userId');echo $userId;
$this->data['Form']['created_by']=$this->Session->read('userId');
$userName=$this->Form->findUserName($this->data);
$this->set('userName',$userName);
}
}
But this User id is not displaying the session variable what i have wrote....
Why its happening..