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
74246a23
Commit
74246a23
authored
Apr 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form wip
parent
9af15ac8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
36 deletions
+41
-36
login.php
app/protected/views/site/login.php
+1
-1
User.php
framework/web/User.php
+1
-1
ActiveField.php
framework/widgets/ActiveField.php
+33
-9
ActiveForm.php
framework/widgets/ActiveForm.php
+6
-25
No files found.
app/protected/views/site/login.php
View file @
74246a23
...
@@ -13,7 +13,7 @@ use yii\helpers\Html;
...
@@ -13,7 +13,7 @@ use yii\helpers\Html;
<?php
$form
=
$this
->
beginWidget
(
'yii\widgets\ActiveForm'
);
?>
<?php
$form
=
$this
->
beginWidget
(
'yii\widgets\ActiveForm'
);
?>
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'username'
)
->
textInput
();
?>
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
checkboxAl
t
();
?>
<?php
echo
$form
->
field
(
$model
,
'password'
)
->
passwordInpu
t
();
?>
<?php
<?php
$field
=
$form
->
field
(
$model
,
'username'
);
$field
=
$form
->
field
(
$model
,
'username'
);
echo
$field
->
begin
()
.
"
\n
"
echo
$field
->
begin
()
.
"
\n
"
...
...
framework/web/User.php
View file @
74246a23
...
@@ -32,7 +32,7 @@ class User extends Component
...
@@ -32,7 +32,7 @@ class User extends Component
const
EVENT_AFTER_LOGOUT
=
'afterLogout'
;
const
EVENT_AFTER_LOGOUT
=
'afterLogout'
;
/**
/**
* @var string the class name o
r alias o
f the [[identity]] object.
* @var string the class name of the [[identity]] object.
*/
*/
public
$identityClass
;
public
$identityClass
;
/**
/**
...
...
framework/widgets/ActiveField.php
View file @
74246a23
...
@@ -36,22 +36,46 @@ class ActiveField extends Component
...
@@ -36,22 +36,46 @@ class ActiveField extends Component
/**
/**
* @var array
* @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
()
public
function
begin
()
{
{
$options
=
$this
->
options
===
null
?
$this
->
form
->
fieldOptions
:
$this
->
options
;
$options
=
$this
->
options
;
$this
->
tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'div'
;
$this
->
tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'div'
;
unset
(
$options
[
'tag'
]);
unset
(
$options
[
'tag'
]);
$class
=
isset
(
$options
[
'class'
])
?
array
(
$options
[
'class'
])
:
array
();
$class
=
isset
(
$options
[
'class'
])
?
array
(
$options
[
'class'
])
:
array
();
if
(
$this
->
form
->
autoFieldCssClass
)
{
if
(
$this
->
autoFieldCssClass
)
{
$class
[]
=
'field-'
.
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
);
$class
[]
=
'field-'
.
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
);
}
}
if
(
$this
->
model
->
isAttributeRequired
(
$this
->
attribute
))
{
if
(
$this
->
model
->
isAttributeRequired
(
$this
->
attribute
))
{
$class
[]
=
$this
->
form
->
requiredCssClass
;
$class
[]
=
$this
->
requiredCssClass
;
}
}
if
(
$this
->
model
->
hasErrors
(
$this
->
attribute
))
{
if
(
$this
->
model
->
hasErrors
(
$this
->
attribute
))
{
$class
[]
=
$this
->
form
->
errorCssClass
;
$class
[]
=
$this
->
errorCssClass
;
}
}
if
(
$class
!==
array
())
{
if
(
$class
!==
array
())
{
$options
[
'class'
]
=
implode
(
' '
,
$class
);
$options
[
'class'
]
=
implode
(
' '
,
$class
);
...
@@ -67,7 +91,7 @@ class ActiveField extends Component
...
@@ -67,7 +91,7 @@ class ActiveField extends Component
public
function
label
(
$options
=
null
)
public
function
label
(
$options
=
null
)
{
{
if
(
$options
===
null
)
{
if
(
$options
===
null
)
{
$options
=
$this
->
form
->
labelOptions
;
$options
=
$this
->
labelOptions
;
}
}
return
Html
::
activeLabel
(
$this
->
model
,
$this
->
attribute
,
$options
);
return
Html
::
activeLabel
(
$this
->
model
,
$this
->
attribute
,
$options
);
}
}
...
@@ -75,7 +99,7 @@ class ActiveField extends Component
...
@@ -75,7 +99,7 @@ class ActiveField extends Component
public
function
error
(
$options
=
null
)
public
function
error
(
$options
=
null
)
{
{
if
(
$options
===
null
)
{
if
(
$options
===
null
)
{
$options
=
$this
->
form
->
errorOptions
;
$options
=
$this
->
errorOptions
;
}
}
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
$error
=
$this
->
model
->
getFirstError
(
$attribute
);
$error
=
$this
->
model
->
getFirstError
(
$attribute
);
...
@@ -89,7 +113,7 @@ class ActiveField extends Component
...
@@ -89,7 +113,7 @@ class ActiveField extends Component
protected
function
render
(
$input
)
protected
function
render
(
$input
)
{
{
return
$this
->
begin
()
.
"
\n
"
.
strtr
(
$this
->
form
->
fieldTemplate
,
array
(
return
$this
->
begin
()
.
"
\n
"
.
strtr
(
$this
->
layout
,
array
(
'{input}'
=>
$input
,
'{input}'
=>
$input
,
'{label}'
=>
$this
->
label
(),
'{label}'
=>
$this
->
label
(),
'{error}'
=>
$this
->
error
(),
'{error}'
=>
$this
->
error
(),
...
...
framework/widgets/ActiveForm.php
View file @
74246a23
...
@@ -31,40 +31,22 @@ class ActiveForm extends Widget
...
@@ -31,40 +31,22 @@ class ActiveForm extends Widget
*/
*/
public
$method
=
'post'
;
public
$method
=
'post'
;
public
$options
=
array
();
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.
* @var string the default CSS class for the error summary container.
* @see errorSummary()
* @see errorSummary()
*/
*/
public
$errorSummaryCssClass
=
'yii-error-summary'
;
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.
* @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
* 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}).
* that support it (see {@link CValidator::enableClientValidation} and {@link CValidator::clientValidateAttribute}).
*/
*/
public
$enableClientValidation
=
false
;
public
$enableClientValidation
=
false
;
public
$fieldClass
=
'yii\widgets\ActiveField'
;
public
$fieldConfig
=
array
(
'class'
=>
'yii\widgets\ActiveField'
,
);
/**
/**
* Initializes the widget.
* Initializes the widget.
* This renders the form open tag.
* This renders the form open tag.
...
@@ -130,12 +112,11 @@ class ActiveForm extends Widget
...
@@ -130,12 +112,11 @@ class ActiveForm extends Widget
public
function
field
(
$model
,
$attribute
,
$options
=
null
)
public
function
field
(
$model
,
$attribute
,
$options
=
null
)
{
{
return
Yii
::
createObject
(
array
(
return
Yii
::
createObject
(
array_merge
(
$this
->
fieldConfig
,
array
(
'class'
=>
$this
->
fieldClass
,
'model'
=>
$model
,
'model'
=>
$model
,
'attribute'
=>
$attribute
,
'attribute'
=>
$attribute
,
'form'
=>
$this
,
'form'
=>
$this
,
'options'
=>
$options
,
'options'
=>
$options
,
));
))
)
;
}
}
}
}
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