Captcha And Behaviours

Hi,

I’m newbie in Yii.

I have read this topic www.yiiframework.com/wiki/208 /how-to-use-an-application-behavior-to-maintain-runtime-configuration/ to use i18N in a single application I have built.

After include in config/main.php (as that post suggest):

[font=“Courier New”] ‘behaviors’ => array(‘ApplicationConfigBehavior’),[/font]

the captcha in form Contact page stops to work.

whether I comment that line “…‘behaviors’ => array(‘ApplicationConfigBehavior’),” captcha comes back to work fine.

Alson I’ve read this topic https: // github.com /yiisoft/yii/issues/733 but could not understand how to solve that problem.

and finally I can not see dropdown list to change language as suggest in the prior post link.

I’m using:

Yii: 1.1.12.b600af

Php: 5.3.6

Apache: 2.2.22 (Win32)

Windows 7 pro 64bits

I’ve tried some encodes (such as ANSI, TUF-8 without BOM) and no success.

Once I’m newbie, I could not put weblink I had research. Sorry.

Any help I would appreciate.

Thanks

Alexandre

Hi Alexandre

I checked this in my localhost and works fine, so

Did you change any of the code of the article in your site?

You have to give more details of your issue.

does the Captcha renders the <img id="yw0" src="…" alt=""> (check this with firebug)

trace the rendered html and tell us which the part of html not rendered.

Hi Konapaz,

Thank you for your prompted answer.

As you can imagine I was wrong, I found out that the right place to put the snipped code “‘behaviors’ => array(‘ApplicationConfigBehavior’),” must be inside ‘components’=>array( … )

instead into the top return array( … )

of (../protected/config/main.php) file.

Captcha works fine now.

Thanks for your help.

But second issue ( www.yiiframework.com/wiki/208 /how-to-use-an-application-behavior-to-maintain-runtime-configuration/) I could not figure out, even I’ve read comment #5842 and #5061.

I change dropbox options among the languages (such as from ‘en’ to ‘pt_br’) and nothing happens.

I just set up ../messages/pt_br folder and the array translation file (I called it translation.php).

Do I need set up at the top of file ../protected/config/main.php?

// language i18N

‘sourceLanguage’=>‘en’,

‘language’=>‘pt_br’,

When I do that (lines above) I can see translated messages, also the drop box appears and I’m able to change its options, but whenever I do that, I see nothing translates.

Any ideas?

Did you check if works setting manually the language?

to do that add this line Yii::app()->language = ‘pt_br’; to init() function into protected/components/controller.php

if the function not exists add

public function init() {Yii::app()->language = ‘pt_br’; }

the in view files use the ‘t’ function Yii:t()

Yii::t(‘translation’, “your message”);

where translation is the translation.php in pt_br/message folder and

‘your message’ exist like ‘your message’=>‘your translation message’

If all works fine check why the language not set by dropbox after of submitted

(I suppose the site refresh after changing of language by dropbox)

Hi Konapaz,

let me show how to I did that so far:

I’ve putted in …/protected/config/main.php, into ‘components’=>array( …

[font=“Courier New”] ‘behaviors’ => array(‘ApplicationConfigBehavior’),[/font]

1- My component controller is called ApplicationConfigBehavior and I’ve putted it in ../protected/components/ApplicationConfigBehavior.php

[font="Courier New"]<?php

class ApplicationConfigBehavior extends CBehavior

{

3391

yii.jpg
public function init() {

Yii::app()-&gt;language = 'pt_br';


}





public function events()


{


	return array_merge(parent::events(), array(


    	'onBeginRequest'=&gt;'beginRequest',


	));


}





public function beginRequest()


{


if (isset(&#036;_POST['_lang']))


       	&#036;this-&gt;owner-&gt;user-&gt;setState('applicationLanguage', &#036;_POST['_lang']);


if (&#036;this-&gt;owner-&gt;user-&gt;getState('applicationLanguage'))


    	&#036;this-&gt;owner-&gt;language=&#036;this-&gt;owner-&gt;user-&gt;getState('applicationLanguage');


	else 


    	&#036;this-&gt;owner-&gt;language='en';


}

}[/font]

2- My widget is called LangBox and I’ve putted it in ../protected/components/LangBox.php

[font="Courier New"]<?php

class LangBox extends CWidget

{

public function run()


{


	&#036;currentLang = Yii::app()-&gt;language;


	&#036;this-&gt;render('langBox', array('currentLang' =&gt; &#036;currentLang));


}

}

?>[/font]

3- My form is called langBox and I’ve putted it in ../protected/components/views/langBox.php

[font="Courier New"]<?php echo CHtml::form(); ?>

&lt;div id=&quot;langdrop&quot;&gt;


	&lt;?php echo CHtml::dropDownList('_lang', &#036;currentLang, array(


    	'en_us' =&gt; 'English', 'pt_br' =&gt; 'Brazilian'), array('submit' =&gt; '')); ?&gt;


&lt;/div&gt;


&lt;div id=&quot;nothing_special&quot;&gt;


&lt;?php //just to check if language has been changed after using dropdown box ?&gt;


&lt;?php echo Yii::app()-&gt;language.&quot;&lt;br/&gt;&quot;.Yii::app()-&gt;sourceLanguage; ?&gt;


&lt;/div&gt;

<?php echo CHtml::endForm(); ?>[/font]

4- In ../protected/views/layouts/main.php I’ve putted the code bellow (before $content line):

[font=“Courier New”] <?php $this->widget(‘LangBox’); // ac? change user’s language ?>

[/font]

All files cited are in UTF-8 enconde.

I can see the dropDown Box, and be able to change the language options.

But whatever I do that (choosing any different language of en_us), the current page takes an brief while refreshing and comes back to en_us (pagination comes back to first page too) as I can see in the form langBox line [font="Courier New"]<?php echo Yii::app()->language."<br/>".Yii::app()->sourceLanguage; ?>[/font]

[font="Courier New"] en_us

en_us[/font]

[center]

[/center]

That is all for now :)

Thanks.

Hi everyone,

Maybe I do not express in the last message.

In other words, I CAN NOT solve that issue, I just explain what I did until there, with NO SUCCESS.

Please, could you help me out?

Thanks.

May you sould use $app->session instead of $this->owner->user->setState, I don’t know why it is not work but you can choose a little different way.

see the related post

http://www.yiiframework.com/wiki/26/setting-and-maintaining-the-language-in-application-i18n

Hi

I have the same problem with the captha not showing after adding a behavior.

You said:


As you can imagine I was wrong, I found out that the right place to put the snipped

code "'behaviors' => array('ApplicationConfigBehavior')," must be

inside 'components'=>array( ... )

instead into the top return array( ... ) of (../protected/config/main.php) file.


Captcha works fine now.



I belief that is wrong.

The reason why the captcha is working now, is because the behavior is NOT working any more. I think Behaviour must come BEFORE ‘components’=>array( … )

So I am still looking for a solution to get captcha working.

I think I found the error.

My behaviour had extra spaces/carriage-returns after the closing ?> tag.




<?php


class myBehavior extends CBehavior

{

...

}

?>


(extra spaces/carriage-returns in the file here)




It must look like this




<?php


class myBehavior extends CBehavior

{

...

}

?>



Even better, I think: take out the ?>




<?php


class myBehavior extends CBehavior

{

...

}



Hi Gerhard

In fact, you’re right. Thanks for explain it to us.

In my case I have no extra blank spaces, returns or php enclosed tags

This morning after I’ve seen your set of messages, I just tried once again and … Everything worked fine!

Amazing… Just like initial sniped code.

I can not explain, might it be any malformed cookie? After its timeout, all kind of stuffs worked here. I don not know!!!

Thanks Konapaz and Gerhard