setFlash wont work with translated messages!

My code




Yii::app()->user->setFlash('success', Yii::t('login', 'Thanks. You are now logged in.'));



will not work.It does not set a flash message (and no Exception thrown),while




Yii::app()->user->setFlash('success','Thanks. You are now logged in.');



will work fine.So the translation function is clearly causing the problem,why?

I am translating to Greek and read messages from database.

Thanks in advance for your help.

Does it work if you do


$translation = Yii::t('login', 'Thanks. You are now logged in.');

Yii::app()->user->setFlash('success', $translation);



If not, do you get anything from


echo Yii::t('login', 'Thanks. You are now logged in.');

Yii::t returns a string, so it should work!

The problem is the charset, that you must define to accept greek letters, or else it will be null

a header in the config file should solve it


header('Content-Type: text/html; charset=someCharset');

also add it to the database and yii config to solve other possible problems


return array(

  'language'=>'...'

  'charset'=>'someCharset'

  'components'=>array(

	'db'=>array(

  	'charset'=>'someCharset'

	),

  ),

);

I think utf-8 will do the trick, but can’t be sure (never wrote anything in greek)

Gustavo and georgebuckinham thank you both for your reply.

in my config/main.php I have already set charset to be UTF-8,so that’s not a problem.See the code from a simple login controller:





if( isset($_POST['LoginForm']) )

		{

			$model->attributes = $_POST['LoginForm'];

			if( $model->validate() )

			{

				// Login

				$identity = new InternalIdentity($model->email, $model->password);

				if($identity->authenticate())

				{


					Yii::app()->user->setFlash('success', Yii::t('login', 'Thanks. You are now logged in.'));

					Yii::app()->user->login($identity, (Yii::app()->params['loggedInDays'] * 60 * 60 * 24 ));

				}

				

				// Redirect

				$this->redirect(Yii::app()->request->baseUrl.'/site/');

			}

		}



.Now, more weirdness:I tried commenting out the redirection after the login,and guess what:My translated flash message appeared!But Of course,no redirection.If I bring in the redirection line:no flash message.I tried moving the setFlash function to every possible position inside the if block,but no luck… thought flash messages are available on the same AND next page.I will appreciate any helpful tip-idea,thanks in advance.

Save the session to database instead of just cookie.

Use CDbHttpSession component.

That’s strange. Below is some very similar code I wrote a while ago, where the flash message does work on login:


if(isset($_POST['LoginForm']))

{

    $model->attributes=$_POST['LoginForm'];

    

    if($model->validate() && $model->login()) {

        // Get the user


        if(Yii::app()->user->checkAccess("data-entry")) {

            $this->redirect(array('/admin/data_entry'));

        } else {

            Yii::app()->user->setFlash('login', "You've been logged in successfully");

            $this->redirect(array('/business/update'));

        }

        

    }

} 

Are you sure that on the page you’re redirecting to, you are checking for a set flash message and then displaying it? Unless you have it in your main template/layout files.

If you have no luck, I suggest setting up a temporary page that just displays the ‘success’ flash message, and redirect to that page on login.

I am already using it,in my config/main.php





 'session' =>  array(

					'class' => 'CDbHttpSession',

					'sessionTableName' => 'sessions',

					'connectionID' => 'db',

                    'cookieParams' => array('domain' => '.' . $current_domain ),

                    'timeout' => 3600,

                    'sessionName' => 'SECSESS',


                ),



It has to do with the translation.Has to be a bug.If I switch the application language to english,eveything works as expected:the un-translated flash message appears on the redirection page.If I switch to Greek,the translated flash message will appear only on the same page.This is totally bizzare,and I think beyond anyone’s ability to resolve,since it is probably a bug.I wont spent more time on this,I will probably write an ajaxified login process.Thanks to everybody who took the time to help me,Cheers!

ISSUE RESOLVED!!!

I use CDbHttpSession for my sessions.

The problem was with my session table,the table and field collation was not set to utf8_general_ci,so my translated flash message could not be stored properly and passed to the redirection page.

Hope that helps someone.

Again,many thanks to everybody who took the time to help me.

Cheers!