Skip to content

Commit 6fd1c16

Browse files
committed
Revert "Added ActiveForm::mfield()."
This reverts commit 9a5ca99.
1 parent f845825 commit 6fd1c16

File tree

7 files changed

+28
-79
lines changed

7 files changed

+28
-79
lines changed

apps/advanced/backend/views/site/login.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
<p>Please fill out the following fields to login:</p>
1616

17-
<?php $form = ActiveForm::begin(array(
18-
'model' => $model,
19-
'options' => array('class' => 'form-horizontal'),
20-
)); ?>
21-
<?php echo $form->field('username')->textInput(); ?>
22-
<?php echo $form->field('password')->passwordInput(); ?>
23-
<?php echo $form->field('rememberMe')->checkbox(); ?>
17+
<?php $form = ActiveForm::begin(array('options' => array('class' => 'form-horizontal'))); ?>
18+
<?php echo $form->field($model, 'username')->textInput(); ?>
19+
<?php echo $form->field($model, 'password')->passwordInput(); ?>
20+
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
2421
<div class="form-actions">
2522
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
2623
</div>

apps/advanced/frontend/views/site/contact.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
</p>
2525

2626
<?php $form = ActiveForm::begin(array(
27-
'model' => $model,
2827
'options' => array('class' => 'form-horizontal'),
2928
'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')),
3029
)); ?>
31-
<?php echo $form->field('name')->textInput(); ?>
32-
<?php echo $form->field('email')->textInput(); ?>
33-
<?php echo $form->field('subject')->textInput(); ?>
34-
<?php echo $form->field('body')->textArea(array('rows' => 6)); ?>
35-
<?php echo $form->field('verifyCode')->widget(Captcha::className(), array(
30+
<?php echo $form->field($model, 'name')->textInput(); ?>
31+
<?php echo $form->field($model, 'email')->textInput(); ?>
32+
<?php echo $form->field($model, 'subject')->textInput(); ?>
33+
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
34+
<?php echo $form->field($model, 'verifyCode')->widget(Captcha::className(), array(
3635
'options' => array('class' => 'input-medium'),
3736
)); ?>
3837
<div class="form-actions">

apps/advanced/frontend/views/site/login.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
<p>Please fill out the following fields to login:</p>
1616

17-
<?php $form = ActiveForm::begin(array(
18-
'model' => $model,
19-
'options' => array('class' => 'form-horizontal'),
20-
)); ?>
21-
<?php echo $form->field('username')->textInput(); ?>
22-
<?php echo $form->field('password')->passwordInput(); ?>
23-
<?php echo $form->field('rememberMe')->checkbox(); ?>
17+
<?php $form = ActiveForm::begin(array('options' => array('class' => 'form-horizontal'))); ?>
18+
<?php echo $form->field($model, 'username')->textInput(); ?>
19+
<?php echo $form->field($model, 'password')->passwordInput(); ?>
20+
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
2421
<div class="form-actions">
2522
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
2623
</div>

apps/basic/views/site/contact.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
</p>
2525

2626
<?php $form = ActiveForm::begin(array(
27-
'model' => $model,
2827
'options' => array('class' => 'form-horizontal'),
2928
'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')),
3029
)); ?>
31-
<?php echo $form->field('name')->textInput(); ?>
32-
<?php echo $form->field('email')->textInput(); ?>
33-
<?php echo $form->field('subject')->textInput(); ?>
34-
<?php echo $form->field('body')->textArea(array('rows' => 6)); ?>
35-
<?php echo $form->field('verifyCode')->widget(Captcha::className(), array(
30+
<?php echo $form->field($model, 'name')->textInput(); ?>
31+
<?php echo $form->field($model, 'email')->textInput(); ?>
32+
<?php echo $form->field($model, 'subject')->textInput(); ?>
33+
<?php echo $form->field($model, 'body')->textArea(array('rows' => 6)); ?>
34+
<?php echo $form->field($model, 'verifyCode')->widget(Captcha::className(), array(
3635
'options' => array('class' => 'input-medium'),
3736
)); ?>
3837
<div class="form-actions">

apps/basic/views/site/login.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
<p>Please fill out the following fields to login:</p>
1616

17-
<?php $form = ActiveForm::begin(array(
18-
'model' => $model,
19-
'options' => array('class' => 'form-horizontal'),
20-
)); ?>
21-
<?php echo $form->field('username')->textInput(); ?>
22-
<?php echo $form->field('password')->passwordInput(); ?>
23-
<?php echo $form->field('rememberMe')->checkbox(); ?>
17+
<?php $form = ActiveForm::begin(array('options' => array('class' => 'form-horizontal'))); ?>
18+
<?php echo $form->field($model, 'username')->textInput(); ?>
19+
<?php echo $form->field($model, 'password')->passwordInput(); ?>
20+
<?php echo $form->field($model, 'rememberMe')->checkbox(); ?>
2421
<div class="form-actions">
2522
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
2623
</div>

docs/guide/upgrade-from-v1.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ is a container consisting of a label, an input, and an error message. It is repr
327327
as an `ActiveField` object. Using fields, you can build a form more cleanly than before:
328328

329329
```php
330-
<?php $form = yii\widgets\ActiveForm::begin(array('model' => $model)); ?>
331-
<?php echo $form->field('username')->textInput(); ?>
332-
<?php echo $form->field('password')->passwordInput(); ?>
330+
<?php $form = yii\widgets\ActiveForm::begin(); ?>
331+
<?php echo $form->field($model, 'username')->textInput(); ?>
332+
<?php echo $form->field($model, 'password')->passwordInput(); ?>
333333
<div class="form-actions">
334334
<?php echo Html::submitButton('Login'); ?>
335335
</div>

framework/yii/widgets/ActiveForm.php

+3-43
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace yii\widgets;
99

1010
use Yii;
11-
use yii\base\InvalidConfigException;
1211
use yii\base\Widget;
1312
use yii\base\Model;
1413
use yii\helpers\Html;
@@ -31,12 +30,6 @@ class ActiveForm extends Widget
3130
* Defaults to 'post'.
3231
*/
3332
public $method = 'post';
34-
/**
35-
* @var Model the model associated with this form. This property must be set if you call [[field()]]
36-
* to create input fields. If a form is associated with multiple models, this property is not needed
37-
* and you should use [[mfield()]] to create input fields.
38-
*/
39-
public $model;
4033
/**
4134
* @var array the HTML attributes (name-value pairs) for the form tag.
4235
* The values will be HTML-encoded using [[Html::encode()]].
@@ -215,50 +208,17 @@ public function errorSummary($models, $options = array())
215208
}
216209

217210
/**
218-
* Generates a form field using [[model]] and the specified attribute.
219-
*
211+
* Generates a form field.
220212
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
221-
* and uses them to interact with end users to collect their input for the attribute.
222-
*
223-
* This method is mainly used for a form with a single model.
224-
*
225-
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
226-
* about attribute expression.
227-
* @param array $options the additional configurations for the field object
228-
* @return ActiveField the created ActiveField object
229-
* @throws InvalidConfigException if [[model]] is not specified
230-
* @see fieldConfig
231-
* @see mfield
232-
*/
233-
public function field($attribute, $options = array())
234-
{
235-
if (!$this->model instanceof Model) {
236-
throw new InvalidConfigException('The "model" property must be set.');
237-
}
238-
return Yii::createObject(array_merge($this->fieldConfig, $options, array(
239-
'model' => $this->model,
240-
'attribute' => $attribute,
241-
'form' => $this,
242-
)));
243-
}
244-
245-
/**
246-
* Generates a form field using the specified model and attribute.
247-
*
248-
* This method differs from [[field()]] in that the model is passed as a parameter rather than obtained
249-
* from [[model]].
250-
*
251-
* This method is mainly used for a form with multiple models.
252-
*
213+
* and use them to interact with end users to collect their inputs for the attribute.
253214
* @param Model $model the data model
254215
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
255216
* about attribute expression.
256217
* @param array $options the additional configurations for the field object
257218
* @return ActiveField the created ActiveField object
258219
* @see fieldConfig
259-
* @see field
260220
*/
261-
public function mfield($model, $attribute, $options = array())
221+
public function field($model, $attribute, $options = array())
262222
{
263223
return Yii::createObject(array_merge($this->fieldConfig, $options, array(
264224
'model' => $model,

0 commit comments

Comments
 (0)