Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
9a5ca995
Commit
9a5ca995
authored
Jun 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ActiveForm::mfield().
parent
c210de9d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
79 additions
and
28 deletions
+79
-28
login.php
apps/advanced/backend/views/site/login.php
+7
-4
contact.php
apps/advanced/frontend/views/site/contact.php
+6
-5
login.php
apps/advanced/frontend/views/site/login.php
+7
-4
contact.php
apps/basic/views/site/contact.php
+6
-5
login.php
apps/basic/views/site/login.php
+7
-4
upgrade-from-v1.md
docs/guide/upgrade-from-v1.md
+3
-3
ActiveForm.php
framework/yii/widgets/ActiveForm.php
+43
-3
No files found.
apps/advanced/backend/views/site/login.php
View file @
9a5ca995
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
Please fill out the following fields to login:
</p>
<p>
Please fill out the following fields to login:
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
)));
?>
<?php
$form
=
ActiveForm
::
begin
(
array
(
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
'model'
=>
$model
,
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInput
();
?>
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
<?php
echo
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
();
?>
));
?>
<?php
echo
$form
->
field
(
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'password'
)
->
passwordInput
();
?>
<?php
echo
$form
->
field
(
'rememberMe'
)
->
checkbox
();
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
</div>
</div>
...
...
apps/advanced/frontend/views/site/contact.php
View file @
9a5ca995
...
@@ -24,14 +24,15 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -24,14 +24,15 @@ $this->params['breadcrumbs'][] = $this->title;
</p>
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
<?php
$form
=
ActiveForm
::
begin
(
array
(
'model'
=>
$model
,
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
));
?>
));
?>
<?php
echo
$form
->
field
(
$model
,
'name'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'name'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'email'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'email'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'subject'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'subject'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'body'
)
->
textArea
(
array
(
'rows'
=>
6
));
?>
<?php
echo
$form
->
field
(
'body'
)
->
textArea
(
array
(
'rows'
=>
6
));
?>
<?php
echo
$form
->
field
(
$model
,
'verifyCode'
)
->
widget
(
Captcha
::
className
(),
array
(
<?php
echo
$form
->
field
(
'verifyCode'
)
->
widget
(
Captcha
::
className
(),
array
(
'options'
=>
array
(
'class'
=>
'input-medium'
),
'options'
=>
array
(
'class'
=>
'input-medium'
),
));
?>
));
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
...
...
apps/advanced/frontend/views/site/login.php
View file @
9a5ca995
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
Please fill out the following fields to login:
</p>
<p>
Please fill out the following fields to login:
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
)));
?>
<?php
$form
=
ActiveForm
::
begin
(
array
(
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
'model'
=>
$model
,
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInput
();
?>
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
<?php
echo
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
();
?>
));
?>
<?php
echo
$form
->
field
(
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'password'
)
->
passwordInput
();
?>
<?php
echo
$form
->
field
(
'rememberMe'
)
->
checkbox
();
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
</div>
</div>
...
...
apps/basic/views/site/contact.php
View file @
9a5ca995
...
@@ -24,14 +24,15 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -24,14 +24,15 @@ $this->params['breadcrumbs'][] = $this->title;
</p>
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
<?php
$form
=
ActiveForm
::
begin
(
array
(
'model'
=>
$model
,
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
'fieldConfig'
=>
array
(
'inputOptions'
=>
array
(
'class'
=>
'input-xlarge'
)),
));
?>
));
?>
<?php
echo
$form
->
field
(
$model
,
'name'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'name'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'email'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'email'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'subject'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'subject'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'body'
)
->
textArea
(
array
(
'rows'
=>
6
));
?>
<?php
echo
$form
->
field
(
'body'
)
->
textArea
(
array
(
'rows'
=>
6
));
?>
<?php
echo
$form
->
field
(
$model
,
'verifyCode'
)
->
widget
(
Captcha
::
className
(),
array
(
<?php
echo
$form
->
field
(
'verifyCode'
)
->
widget
(
Captcha
::
className
(),
array
(
'options'
=>
array
(
'class'
=>
'input-medium'
),
'options'
=>
array
(
'class'
=>
'input-medium'
),
));
?>
));
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
...
...
apps/basic/views/site/login.php
View file @
9a5ca995
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
...
@@ -14,10 +14,13 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
Please fill out the following fields to login:
</p>
<p>
Please fill out the following fields to login:
</p>
<?php
$form
=
ActiveForm
::
begin
(
array
(
'options'
=>
array
(
'class'
=>
'form-horizontal'
)));
?>
<?php
$form
=
ActiveForm
::
begin
(
array
(
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
'model'
=>
$model
,
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInput
();
?>
'options'
=>
array
(
'class'
=>
'form-horizontal'
),
<?php
echo
$form
->
field
(
$model
,
'rememberMe'
)
->
checkbox
();
?>
));
?>
<?php
echo
$form
->
field
(
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'password'
)
->
passwordInput
();
?>
<?php
echo
$form
->
field
(
'rememberMe'
)
->
checkbox
();
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
<?php
echo
Html
::
submitButton
(
'Login'
,
null
,
null
,
array
(
'class'
=>
'btn btn-primary'
));
?>
</div>
</div>
...
...
docs/guide/upgrade-from-v1.md
View file @
9a5ca995
...
@@ -327,9 +327,9 @@ is a container consisting of a label, an input, and an error message. It is repr
...
@@ -327,9 +327,9 @@ is a container consisting of a label, an input, and an error message. It is repr
as an
`ActiveField`
object. Using fields, you can build a form more cleanly than before:
as an
`ActiveField`
object. Using fields, you can build a form more cleanly than before:
```
php
```
php
<?php
$form
=
yii\widgets\ActiveForm
::
begin
();
?>
<?php
$form
=
yii\widgets\ActiveForm
::
begin
(
array
(
'model'
=>
$model
)
);
?>
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInput
();
?>
<?php
echo
$form
->
field
(
'password'
)
->
passwordInput
();
?>
<div
class=
"form-actions"
>
<div
class=
"form-actions"
>
<?php
echo
Html
::
submitButton
(
'Login'
);
?>
<?php
echo
Html
::
submitButton
(
'Login'
);
?>
</div>
</div>
...
...
framework/yii/widgets/ActiveForm.php
View file @
9a5ca995
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
yii\widgets
;
namespace
yii\widgets
;
use
Yii
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\base\Widget
;
use
yii\base\Widget
;
use
yii\base\Model
;
use
yii\base\Model
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
...
@@ -31,6 +32,12 @@ class ActiveForm extends Widget
...
@@ -31,6 +32,12 @@ class ActiveForm extends Widget
*/
*/
public
$method
=
'post'
;
public
$method
=
'post'
;
/**
/**
* @var Model the model associated with this form. This property must be set if you call [[field()]]
* to create input fields. If a form is associated with multiple models, this property is not needed
* and you should use [[mfield()]] to create input fields.
*/
public
$model
;
/**
* @var array the HTML attributes (name-value pairs) for the form tag.
* @var array the HTML attributes (name-value pairs) for the form tag.
* The values will be HTML-encoded using [[Html::encode()]].
* The values will be HTML-encoded using [[Html::encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* If a value is null, the corresponding attribute will not be rendered.
...
@@ -208,17 +215,50 @@ class ActiveForm extends Widget
...
@@ -208,17 +215,50 @@ class ActiveForm extends Widget
}
}
/**
/**
* Generates a form field.
* Generates a form field using [[model]] and the specified attribute.
*
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
* A form field is associated with a model and an attribute. It contains a label, an input and an error message
* and use them to interact with end users to collect their inputs for the attribute.
* and uses them to interact with end users to collect their input for the attribute.
*
* This method is mainly used for a form with a single model.
*
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* @param array $options the additional configurations for the field object
* @return ActiveField the created ActiveField object
* @throws InvalidConfigException if [[model]] is not specified
* @see fieldConfig
* @see mfield
*/
public
function
field
(
$attribute
,
$options
=
array
())
{
if
(
!
$this
->
model
instanceof
Model
)
{
throw
new
InvalidConfigException
(
'The "model" property must be set.'
);
}
return
Yii
::
createObject
(
array_merge
(
$this
->
fieldConfig
,
$options
,
array
(
'model'
=>
$this
->
model
,
'attribute'
=>
$attribute
,
'form'
=>
$this
,
)));
}
/**
* Generates a form field using the specified model and attribute.
*
* This method differs from [[field()]] in that the model is passed as a parameter rather than obtained
* from [[model]].
*
* This method is mainly used for a form with multiple models.
*
* @param Model $model the data model
* @param Model $model the data model
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* @param string $attribute the attribute name or expression. See [[Html::getAttributeName()]] for the format
* about attribute expression.
* about attribute expression.
* @param array $options the additional configurations for the field object
* @param array $options the additional configurations for the field object
* @return ActiveField the created ActiveField object
* @return ActiveField the created ActiveField object
* @see fieldConfig
* @see fieldConfig
* @see field
*/
*/
public
function
field
(
$model
,
$attribute
,
$options
=
array
())
public
function
m
field
(
$model
,
$attribute
,
$options
=
array
())
{
{
return
Yii
::
createObject
(
array_merge
(
$this
->
fieldConfig
,
$options
,
array
(
return
Yii
::
createObject
(
array_merge
(
$this
->
fieldConfig
,
$options
,
array
(
'model'
=>
$model
,
'model'
=>
$model
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment