models:
代码语言:javascript复制<?php
namespace frontendmodels;
use yiibaseModel;
class LoginForm extends Model
{
public $captcha;
public function rules()
{
return [
['captcha','captcha']
];
}
}
控制器:
代码语言:javascript复制<?php
namespace frontendcontrollers;
use Yii;
use frontendmodelsLoginForm;
class IndexController extends yiiwebController
{
public function actionSite()
{
$model=new LoginForm();
return $this->render('site',[
'model'=>$model
]);
}
}
视图:
代码语言:javascript复制<?php
$form=yiibootstrapActiveForm::begin();
?>
<?=
$form->field($model,'captcha')->widget(yiicaptchaCaptcha::className(),[
'template'=>"{input}{image}"
]);
?>
<?= yiibootstrapHtml::submitButton("登录")?>
<?php yiibootstrapActiveForm::end();?>