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
4ec95e6d
Commit
4ec95e6d
authored
Jul 05, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #600.
parent
1e93fcf2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
AutoTimestamp.php
framework/yii/behaviors/AutoTimestamp.php
+9
-11
No files found.
framework/yii/behaviors/AutoTimestamp.php
View file @
4ec95e6d
...
...
@@ -8,6 +8,7 @@
namespace
yii\behaviors
;
use
yii\base\Behavior
;
use
yii\base\Event
;
use
yii\db\Expression
;
use
yii\db\ActiveRecord
;
...
...
@@ -64,30 +65,27 @@ class AutoTimestamp extends Behavior
*/
public
function
events
()
{
$events
=
array
();
$behavior
=
$this
;
foreach
(
$this
->
attributes
as
$event
=>
$attributes
)
{
if
(
!
is_array
(
$attributes
))
{
$attributes
=
array
(
$attributes
);
}
$events
[
$event
]
=
function
()
use
(
$behavior
,
$attributes
)
{
$behavior
->
updateTimestamp
(
$attributes
);
};
$events
=
$this
->
attributes
;
foreach
(
$events
as
$i
=>
$event
)
{
$events
[
$i
]
=
'updateTimestamp'
;
}
return
$events
;
}
/**
* Updates the attributes with the current timestamp.
* @param
array $attributes list of attributes to be updated.
* @param
Event $event
*/
public
function
updateTimestamp
(
$
attributes
)
public
function
updateTimestamp
(
$
event
)
{
$attributes
=
isset
(
$this
->
attributes
[
$event
->
name
])
?
(
array
)
$this
->
attributes
[
$event
->
name
]
:
array
();
if
(
!
empty
(
$attributes
))
{
$timestamp
=
$this
->
evaluateTimestamp
();
foreach
(
$attributes
as
$attribute
)
{
$this
->
owner
->
$attribute
=
$timestamp
;
}
}
}
/**
* Gets the current timestamp.
...
...
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