diff --git a/app/protected/views/site/login.php b/app/protected/views/site/login.php index a2882a0..3ddd30a 100644 --- a/app/protected/views/site/login.php +++ b/app/protected/views/site/login.php @@ -13,7 +13,7 @@ use yii\helpers\Html; beginWidget('yii\widgets\ActiveForm'); ?> field($model, 'username')->textInput(); ?> - field($model, 'password')->checkboxAlt(); ?> + field($model, 'password')->passwordInput(); ?> field($model, 'username'); echo $field->begin() . "\n" diff --git a/framework/web/User.php b/framework/web/User.php index e997b88..b8bf7cd 100644 --- a/framework/web/User.php +++ b/framework/web/User.php @@ -32,7 +32,7 @@ class User extends Component const EVENT_AFTER_LOGOUT = 'afterLogout'; /** - * @var string the class name or alias of the [[identity]] object. + * @var string the class name of the [[identity]] object. */ public $identityClass; /** diff --git a/framework/widgets/ActiveField.php b/framework/widgets/ActiveField.php index fc19d50..2f07c92 100644 --- a/framework/widgets/ActiveField.php +++ b/framework/widgets/ActiveField.php @@ -36,22 +36,46 @@ class ActiveField extends Component /** * @var array */ - public $options; - + public $options = array( + 'tag' => 'div', + 'class' => 'yii-field', + ); + public $autoFieldCssClass = true; + /** + * @var string the default CSS class that indicates an input is required. + */ + public $requiredCssClass = 'required'; + /** + * @var string the default CSS class that indicates an input has error. + */ + public $errorCssClass = 'error'; + /** + * @var string the default CSS class that indicates an input validated successfully. + */ + public $successCssClass = 'success'; + /** + * @var string the default CSS class that indicates an input is currently being validated. + */ + public $validatingCssClass = 'validating'; + public $layout = "{label}\n{input}\n{error}"; + + public $errorOptions = array('tag' => 'span', 'class' => 'yii-error-message'); + public $labelOptions = array('class' => 'control-label'); + public function begin() { - $options = $this->options === null ? $this->form->fieldOptions : $this->options; + $options = $this->options; $this->tag = isset($options['tag']) ? $options['tag'] : 'div'; unset($options['tag']); $class = isset($options['class']) ? array($options['class']) : array(); - if ($this->form->autoFieldCssClass) { + if ($this->autoFieldCssClass) { $class[] = 'field-' . Html::getInputId($this->model, $this->attribute); } if ($this->model->isAttributeRequired($this->attribute)) { - $class[] = $this->form->requiredCssClass; + $class[] = $this->requiredCssClass; } if ($this->model->hasErrors($this->attribute)) { - $class[] = $this->form->errorCssClass; + $class[] = $this->errorCssClass; } if ($class !== array()) { $options['class'] = implode(' ', $class); @@ -67,7 +91,7 @@ class ActiveField extends Component public function label($options = null) { if ($options === null) { - $options = $this->form->labelOptions; + $options = $this->labelOptions; } return Html::activeLabel($this->model, $this->attribute, $options); } @@ -75,7 +99,7 @@ class ActiveField extends Component public function error($options = null) { if ($options === null) { - $options = $this->form->errorOptions; + $options = $this->errorOptions; } $attribute = Html::getAttributeName($this->attribute); $error = $this->model->getFirstError($attribute); @@ -89,7 +113,7 @@ class ActiveField extends Component protected function render($input) { - return $this->begin() . "\n" . strtr($this->form->fieldTemplate, array( + return $this->begin() . "\n" . strtr($this->layout, array( '{input}' => $input, '{label}' => $this->label(), '{error}' => $this->error(), diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index 6bbee3f..06549a2 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -31,40 +31,22 @@ class ActiveForm extends Widget */ public $method = 'post'; public $options = array(); - public $fieldOptions = array('tag' => 'div', 'class' => 'yii-field'); - public $fieldTemplate = "{label}\n{input}\n{error}"; - public $autoFieldCssClass = true; - public $errorOptions = array('tag' => 'span', 'class' => 'yii-error-message'); - public $labelOptions = array('class' => 'control-label'); /** * @var string the default CSS class for the error summary container. * @see errorSummary() */ public $errorSummaryCssClass = 'yii-error-summary'; /** - * @var string the default CSS class that indicates an input is required. - */ - public $requiredCssClass = 'required'; - /** - * @var string the default CSS class that indicates an input has error. - */ - public $errorCssClass = 'error'; - /** - * @var string the default CSS class that indicates an input validated successfully. - */ - public $successCssClass = 'success'; - /** - * @var string the default CSS class that indicates an input is currently being validated. - */ - public $validatingCssClass = 'validating'; - /** * @var boolean whether to enable client-side data validation. Defaults to false. * When this property is set true, client-side validation will be performed by validators * that support it (see {@link CValidator::enableClientValidation} and {@link CValidator::clientValidateAttribute}). */ public $enableClientValidation = false; - public $fieldClass = 'yii\widgets\ActiveField'; + public $fieldConfig = array( + 'class' => 'yii\widgets\ActiveField', + ); + /** * Initializes the widget. * This renders the form open tag. @@ -130,12 +112,11 @@ class ActiveForm extends Widget public function field($model, $attribute, $options = null) { - return Yii::createObject(array( - 'class' => $this->fieldClass, + return Yii::createObject(array_merge($this->fieldConfig, array( 'model' => $model, 'attribute' => $attribute, 'form' => $this, 'options' => $options, - )); + ))); } }