Reputation: 271
After i used multiple layouts in my app , then Cpatcha not display any image :(
This my code
Controller :
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
model :
public function rules()
{
return array(
array('email, password', 'required','message'=>'-- {attribute} '),
array('password', 'authenticate'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'message'=>' {attribute} Error '),
);
}
view call widget
...
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
...
I tested it on request recorder and it sent and received requests .
Thanks in advance
Upvotes: 1
Views: 1451
Reputation: 271
I fixed it by add Remove Bom Function
ob_start('My_OB');
function My_OB($str, $flags)
{
//remove UTF-8 BOM
$str = preg_replace("/\xef\xbb\xbf/","",$str);
return $str;
}
I guess the problem was in page encoding .
Upvotes: 1
Reputation: 5923
If you are using access control, it is most likely that you are not setting accessRules
for the captcha action. You need to add the action, something like:
public function accessRules() {
return array(
array('allow', // all users
'actions' => ("captcha"),
'users' => array('*'),
),
array('allow', // authenticated users
'actions' => ("captcha"),
'users' => array('@'),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}
Upvotes: 0