Yii验证码不显示刷新按钮
我有一个应用程序,我使用主题来管理不同的样式和布局。在默认生成的contact.php中,我使用以下代码为表单生成验证码验证:Yii验证码不显示刷新按钮,yii,captcha,Yii,Captcha,我有一个应用程序,我使用主题来管理不同的样式和布局。在默认生成的contact.php中,我使用以下代码为表单生成验证码验证: //webroot/themes/botany/views/site/contact.php <?php //echo $form->labelEx($model,'verifyCode'); ?> <div> <?php $this->widget('CCaptc
//webroot/themes/botany/views/site/contact.php
<?php //echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha', array('showRefreshButton' => true,
'buttonLabel' => 'Refresh',
'buttonOptions' => '',
'buttonType' => 'button',
'clickableImage' => true));
?>
<?php echo $form->textField($model,'verifyCode', array('class' => 'form-control', 'placeholder' => 'Captcha*')); ?>
</div>
<p>Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</p>
<?php echo $form->error($model,'verifyCode'); ?>
<?php endif; ?>
//webroot/themes/植物学/views/site/contact.php
请输入上图所示的字母。
字母不区分大小写
虽然我已经设置了showRefreshButton=>true
但我无法看到刷新按钮。下面的屏幕截图显示没有刷新按钮:
经过一些检查,我发现,我认为,Yii中有一个bug,不同的小部件生成具有相同id的HTML元素 在我的例子中,
webroot/themes/植物学/views/layouts/main.php中的zii.widgets.CMenu
widgets为导航菜单的ul
生成相同的id,并且验证码小部件生成的jquery视为验证码小部件图像id
我可以通过提供CMenu的id选项来解决这个问题
<?php $this->widget('zii.widgets.CMenu',array(
'id' => 'gds',
'htmlOptions' => array('class' => 'nav'),
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
array('label'=>'Contact', 'url'=>array('/site/contact')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
),
)); ?>
您使用了什么类型的渲染功能?如果您使用的是renderPartial,它将不会显示“刷新”按钮。简单的方法是创建一个新的空白布局并使用render()
<?php $this->widget('CCaptcha', array('imageOptions' => array('id' => 'yw0'),'showRefreshButton' => true,'buttonLabel' => 'Refresh', 'buttonOptions' => '', 'buttonType' => 'button')); ?>