Hidden Field In Form

Hi i have a form with an hidden filed where i get the user’s email , when the session expired and i refresh the page i have a CEexception :




Property "RWebUser.email" is not defined. 



This is the view :





<?php

/* @var $this FilmController */

/* @var $model Film */


$this->breadcrumbs=array(

	'Films'=>array('index'),

	'Inserisci',

);

/*

$this->menu=array(

	array('label'=>'List Film', 'url'=>array('index')),

	array('label'=>'Manage Film', 'url'=>array('admin')),

);

*/

?>

<?php //if (Yii::app()->user->email==null): ?>

<h2>Sessione scaduta riesegui il login</h2>  (session expired IN ITALIAN)


<?php //$this->redirect('film/index') ?>

	

<?php //else: ?>




<h1>Inserisci Film</h1>


<?php $this->renderPartial('_form', array('model'=>$model)); ?>


<?php //endif ?>



I try to insert an if (code commented ) with :


(Yii::app()->user->email==null)

to redirect to index but dont’work

Yii::app()->user is a component, it does not have an email itself.

You need either get user record from DB (probably storing it somewhere) or use setState/getState.

Exmaple:

This goes to UserIdentity (after $user was loaded from DB)


$this->setState('email', $user->email);

This goes to RWebUser


function getEmail()

{

    return $this->getState('email');

}

Sorry perhaps i dont understand (my english its no good)

I use user modules to manage user.I want only user logged can create a new film , if session expired user is guest and it’s dont have an email ,i cannot get email from db because i dont know who is the user , i want only prevent the CEexception .I want redirect the guest to the index .

Bye tanks

The you dont need an email. Either restrict access to your action to authorized users only using AccessControl filter, or check Yii::app()->user->isGuest.