Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
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
夏彬
yii2bootstrap
Commits
f78a77df
Commit
f78a77df
authored
Aug 06, 2013
by
Suralc
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2 into add-tests
parents
f7bb54be
6c3f2390
Changes
73
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
73 changed files
with
1327 additions
and
340 deletions
+1327
-340
main.php
apps/advanced/backend/views/layouts/main.php
+1
-1
site.css
apps/advanced/backend/web/css/site.css
+6
-6
SiteController.php
apps/advanced/frontend/controllers/SiteController.php
+1
-1
passwordResetToken.php
apps/advanced/frontend/views/emails/passwordResetToken.php
+1
-1
main.php
apps/advanced/frontend/views/layouts/main.php
+1
-1
contact.php
apps/advanced/frontend/views/site/contact.php
+1
-1
site.css
apps/advanced/frontend/web/css/site.css
+6
-6
SiteController.php
apps/basic/controllers/SiteController.php
+1
-1
main.php
apps/basic/views/layouts/main.php
+1
-1
contact.php
apps/basic/views/site/contact.php
+1
-1
site.css
apps/basic/web/css/site.css
+6
-6
controller.md
docs/guide/controller.md
+3
-0
installation.md
docs/guide/installation.md
+17
-2
overview.md
docs/guide/overview.md
+7
-3
performance.md
docs/guide/performance.md
+2
-0
security.md
docs/guide/security.md
+81
-0
composer.json
extensions/twig/composer.json
+1
-1
assets.php
framework/yii/assets.php
+1
-1
yii.captcha.js
framework/yii/assets/yii.captcha.js
+1
-1
Application.php
framework/yii/base/Application.php
+12
-1
Component.php
framework/yii/base/Component.php
+22
-22
ErrorHandler.php
framework/yii/base/ErrorHandler.php
+10
-5
Formatter.php
framework/yii/base/Formatter.php
+22
-8
Model.php
framework/yii/base/Model.php
+2
-2
Module.php
framework/yii/base/Module.php
+1
-7
Object.php
framework/yii/base/Object.php
+12
-12
Carousel.php
framework/yii/bootstrap/Carousel.php
+1
-1
Collapse.php
framework/yii/bootstrap/Collapse.php
+3
-3
Nav.php
framework/yii/bootstrap/Nav.php
+1
-0
NavBar.php
framework/yii/bootstrap/NavBar.php
+1
-1
Progress.php
framework/yii/bootstrap/Progress.php
+1
-1
Tabs.php
framework/yii/bootstrap/Tabs.php
+1
-1
Captcha.php
framework/yii/captcha/Captcha.php
+3
-2
CaptchaAction.php
framework/yii/captcha/CaptchaAction.php
+9
-8
CaptchaAsset.php
framework/yii/captcha/CaptchaAsset.php
+2
-1
CaptchaValidator.php
framework/yii/captcha/CaptchaValidator.php
+4
-2
SpicyRice.md
framework/yii/captcha/SpicyRice.md
+0
-0
SpicyRice.ttf
framework/yii/captcha/SpicyRice.ttf
+0
-0
classes.php
framework/yii/classes.php
+11
-5
HelpController.php
framework/yii/console/controllers/HelpController.php
+1
-1
ActiveDataProvider.php
framework/yii/data/ActiveDataProvider.php
+56
-49
ArrayDataProvider.php
framework/yii/data/ArrayDataProvider.php
+45
-51
DataProvider.php
framework/yii/data/DataProvider.php
+3
-3
IDataProvider.php
framework/yii/data/IDataProvider.php
+10
-10
Sort.php
framework/yii/data/Sort.php
+7
-6
ActiveQuery.php
framework/yii/db/ActiveQuery.php
+9
-5
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+12
-2
Command.php
framework/yii/db/Command.php
+4
-8
Connection.php
framework/yii/db/Connection.php
+1
-3
LogPanel.php
framework/yii/debug/panels/LogPanel.php
+1
-1
ProfilingPanel.php
framework/yii/debug/panels/ProfilingPanel.php
+2
-2
RequestPanel.php
framework/yii/debug/panels/RequestPanel.php
+17
-0
HtmlBase.php
framework/yii/helpers/HtmlBase.php
+3
-2
SecurityBase.php
framework/yii/helpers/SecurityBase.php
+4
-1
requirements.php
framework/yii/requirements/requirements.php
+1
-1
Validator.php
framework/yii/validators/Validator.php
+1
-1
callStackItem.php
framework/yii/views/errorHandler/callStackItem.php
+5
-5
error.php
framework/yii/views/errorHandler/error.php
+16
-13
exception.php
framework/yii/views/errorHandler/exception.php
+21
-26
previousException.php
framework/yii/views/errorHandler/previousException.php
+6
-6
Request.php
framework/yii/web/Request.php
+1
-1
Response.php
framework/yii/web/Response.php
+0
-1
DetailView.php
framework/yii/widgets/DetailView.php
+3
-3
GridView.php
framework/yii/widgets/GridView.php
+328
-0
ListView.php
framework/yii/widgets/ListView.php
+14
-14
ListViewBase.php
framework/yii/widgets/ListViewBase.php
+5
-4
CheckboxColumn.php
framework/yii/widgets/grid/CheckboxColumn.php
+191
-0
Column.php
framework/yii/widgets/grid/Column.php
+147
-0
DataColumn.php
framework/yii/widgets/grid/DataColumn.php
+94
-0
SerialColumn.php
framework/yii/widgets/grid/SerialColumn.php
+32
-0
Singer.php
tests/unit/data/base/Singer.php
+1
-1
FormatterTest.php
tests/unit/framework/base/FormatterTest.php
+10
-0
ActiveDataProviderTest.php
tests/unit/framework/data/ActiveDataProviderTest.php
+19
-4
No files found.
apps/advanced/backend/views/layouts/main.php
View file @
f78a77df
...
...
@@ -24,7 +24,7 @@ AppAsset::register($this);
<div
class=
"masthead"
>
<h3
class=
"muted"
>
My Company
</h3>
<div
class=
"navbar"
>
<div
class=
"navbar
fullwidth
"
>
<div
class=
"navbar-inner"
>
<div
class=
"container"
>
<?php
echo
Menu
::
widget
(
array
(
...
...
apps/advanced/backend/web/css/site.css
View file @
f78a77df
...
...
@@ -44,35 +44,35 @@ body {
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar
.navbar-inner
{
.navbar
.fullwidth
.navbar-inner
{
padding
:
0
;
}
.navbar
.nav
{
.navbar
.fullwidth
.nav
{
margin
:
0
;
display
:
table
;
width
:
100%
;
}
.navbar
.nav
li
{
.navbar
.fullwidth
.nav
li
{
display
:
table-cell
;
width
:
1%
;
float
:
none
;
}
.navbar
.nav
li
a
{
.navbar
.fullwidth
.nav
li
a
{
font-weight
:
bold
;
text-align
:
center
;
border-left
:
1px
solid
rgba
(
255
,
255
,
255
,
.75
);
border-right
:
1px
solid
rgba
(
0
,
0
,
0
,
.1
);
}
.navbar
.nav
li
:first-child
a
{
.navbar
.fullwidth
.nav
li
:first-child
a
{
border-left
:
0
;
border-radius
:
3px
0
0
3px
;
}
.navbar
.nav
li
:last-child
a
{
.navbar
.fullwidth
.nav
li
:last-child
a
{
border-right
:
0
;
border-radius
:
0
3px
3px
0
;
}
apps/advanced/frontend/controllers/SiteController.php
View file @
f78a77df
...
...
@@ -16,7 +16,7 @@ class SiteController extends Controller
{
return
array
(
'captcha'
=>
array
(
'class'
=>
'yii\
web
\CaptchaAction'
,
'class'
=>
'yii\
captcha
\CaptchaAction'
,
),
);
}
...
...
apps/advanced/frontend/views/emails/passwordResetToken.php
View file @
f78a77df
...
...
@@ -6,7 +6,7 @@ use yii\helpers\Html;
* @var common\models\User $user;
*/
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
(
'site/reset
P
assword'
,
array
(
'token'
=>
$user
->
password_reset_token
));
$resetLink
=
Yii
::
$app
->
urlManager
->
createAbsoluteUrl
(
'site/reset
-p
assword'
,
array
(
'token'
=>
$user
->
password_reset_token
));
?>
Hello
<?php
echo
Html
::
encode
(
$user
->
username
)
?>
,
...
...
apps/advanced/frontend/views/layouts/main.php
View file @
f78a77df
...
...
@@ -25,7 +25,7 @@ AppAsset::register($this);
<div
class=
"masthead"
>
<h3
class=
"muted"
>
My Company
</h3>
<div
class=
"navbar"
>
<div
class=
"navbar
fullwidth
"
>
<div
class=
"navbar-inner"
>
<div
class=
"container"
>
<?php
...
...
apps/advanced/frontend/views/site/contact.php
View file @
f78a77df
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
yii\
widgets
\Captcha
;
use
yii\
captcha
\Captcha
;
/**
* @var yii\base\View $this
...
...
apps/advanced/frontend/web/css/site.css
View file @
f78a77df
...
...
@@ -44,35 +44,35 @@ body {
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar
.navbar-inner
{
.navbar
.fullwidth
.navbar-inner
{
padding
:
0
;
}
.navbar
.nav
{
.navbar
.fullwidth
.nav
{
margin
:
0
;
display
:
table
;
width
:
100%
;
}
.navbar
.nav
li
{
.navbar
.fullwidth
.nav
li
{
display
:
table-cell
;
width
:
1%
;
float
:
none
;
}
.navbar
.nav
li
a
{
.navbar
.fullwidth
.nav
li
a
{
font-weight
:
bold
;
text-align
:
center
;
border-left
:
1px
solid
rgba
(
255
,
255
,
255
,
.75
);
border-right
:
1px
solid
rgba
(
0
,
0
,
0
,
.1
);
}
.navbar
.nav
li
:first-child
a
{
.navbar
.fullwidth
.nav
li
:first-child
a
{
border-left
:
0
;
border-radius
:
3px
0
0
3px
;
}
.navbar
.nav
li
:last-child
a
{
.navbar
.fullwidth
.nav
li
:last-child
a
{
border-right
:
0
;
border-radius
:
0
3px
3px
0
;
}
apps/basic/controllers/SiteController.php
View file @
f78a77df
...
...
@@ -13,7 +13,7 @@ class SiteController extends Controller
{
return
array
(
'captcha'
=>
array
(
'class'
=>
'yii\
web
\CaptchaAction'
,
'class'
=>
'yii\
captcha
\CaptchaAction'
,
'fixedVerifyCode'
=>
YII_ENV_DEV
?
'testme'
:
null
,
),
);
...
...
apps/basic/views/layouts/main.php
View file @
f78a77df
...
...
@@ -23,7 +23,7 @@ app\config\AppAsset::register($this);
<div
class=
"masthead"
>
<h3
class=
"muted"
>
My Company
</h3>
<div
class=
"navbar"
>
<div
class=
"navbar
fullwidth
"
>
<div
class=
"navbar-inner"
>
<div
class=
"container"
>
<?php
echo
Menu
::
widget
(
array
(
...
...
apps/basic/views/site/contact.php
View file @
f78a77df
<?php
use
yii\helpers\Html
;
use
yii\widgets\ActiveForm
;
use
yii\
widgets
\Captcha
;
use
yii\
captcha
\Captcha
;
/**
* @var yii\base\View $this
...
...
apps/basic/web/css/site.css
View file @
f78a77df
...
...
@@ -44,35 +44,35 @@ body {
}
/* Customize the navbar links to be fill the entire space of the .navbar */
.navbar
.navbar-inner
{
.navbar
.fullwidth
.navbar-inner
{
padding
:
0
;
}
.navbar
.nav
{
.navbar
.fullwidth
.nav
{
margin
:
0
;
display
:
table
;
width
:
100%
;
}
.navbar
.nav
li
{
.navbar
.fullwidth
.nav
li
{
display
:
table-cell
;
width
:
1%
;
float
:
none
;
}
.navbar
.nav
li
a
{
.navbar
.fullwidth
.nav
li
a
{
font-weight
:
bold
;
text-align
:
center
;
border-left
:
1px
solid
rgba
(
255
,
255
,
255
,
.75
);
border-right
:
1px
solid
rgba
(
0
,
0
,
0
,
.1
);
}
.navbar
.nav
li
:first-child
a
{
.navbar
.fullwidth
.nav
li
:first-child
a
{
border-left
:
0
;
border-radius
:
3px
0
0
3px
;
}
.navbar
.nav
li
:last-child
a
{
.navbar
.fullwidth
.nav
li
:last-child
a
{
border-right
:
0
;
border-radius
:
0
3px
3px
0
;
}
docs/guide/controller.md
View file @
f78a77df
...
...
@@ -50,6 +50,9 @@ If controller is located inside a module its action internal route will be `modu
In case module, controller or action specified isn't found Yii will return "not found" page and HTTP status code 404.
> Note: If controller name or action name contains camelCased words, internal route will use dashes i.e. for
`DateTimeController::actionFastForward`
route will be
`date-time/fast-forward`
.
### Defaults
If user isn't specifying any route i.e. using URL like
`http://example.com/`
, Yii assumes that default route should be
...
...
docs/guide/installation.md
View file @
f78a77df
Installation
============
Installation of Yii mainly involves the following two steps:
Installing via Composer
-----------------------
The recommended way of installing Yii is by using Composer package manager.
There are two application templates available:
-
[
basic
](
https://github.com/yiisoft/yii2-app-basic
)
that is just a basic frontend application template.
-
[
advanced
](
https://github.com/yiisoft/yii2-app-advanced
)
that is a set of frontend, backend, console, common
(shared code) and environments support.
Please refer to installation instructions on these pages.
Installing from zip
-------------------
Installation from zip mainly involves the following two steps:
1.
Download Yii Framework from
[
yiiframework.com
](
http://www.yiiframework.com/
)
.
2.
Unpack the Yii release file to a Web-accessible directory.
...
...
@@ -12,7 +28,6 @@ needs to be exposed to Web users. Other PHP scripts, including those from
Yii, should be protected from Web access; otherwise they might be exploited
by hackers.
Requirements
------------
...
...
docs/guide/overview.md
View file @
f78a77df
...
...
@@ -31,6 +31,10 @@ management systems (CMS), e-commerce systems, etc.
How does Yii Compare with Other Frameworks?
-------------------------------------------
Like most PHP frameworks, Yii is an MVC (Model-View-Controller) framework.
TBD
\ No newline at end of file
-
Like most PHP frameworks, Yii is an MVC (Model-View-Controller) framework.
-
It is a fullstack framework providing many solutions and components such as logging, session management, caching etc.
-
It has a good balance of simplicity and features.
-
Syntax and overall development usability are taken seriously.
-
Performance is one of the key goals.
-
We are constantly watching other web frameworks out there and getting the best ideas in. Initial Yii release was heavily
influenced by Ruby on Rails. Still, we aren't blindly copying anyhting.
\ No newline at end of file
docs/guide/performance.md
View file @
f78a77df
...
...
@@ -100,6 +100,8 @@ You can use `CacheSession` to store sessions using cache. Note that some
cache storage such as memcached has no guarantee that session data will not
be lost leading to unexpected logouts.
If you have
[
Redis
](
http://redis.io/
)
on your server, it's highly recommended as session storage.
Improving application
---------------------
...
...
docs/guide/security.md
View file @
f78a77df
Security
========
Hashing and verifyig passwords
------------------------------
It is important not to store passwords in plain text but, contrary to popular belief, just using
`md5`
or
`sha1`
to
compute and verify hashes isn't a good way either. Modern hardware allows to brute force these very fast.
In order to truly secure user passwords even in case your database is leaked you need to use a function that is resistant
to brute-force such as bcrypt. In PHP it can be achieved by using
[
crypt function
](
http://php.net/manual/en/function.crypt.php
)
but since usage isn't trivial and one can easily misuse it, Yii provides two helper functions for generating hash from
password and verifying existing hash.
When user sets his password we're taking password string from POST and then getting a hash:
```
php
$hash
=
\yii\helpers\Security
::
generatePasswordHash
(
$password
);
```
The hash we've got is persisted to database to be used later.
Then when user is trying to log in we're verifying the password he entered against a hash that we've previously persisted:
```
php
if
(
Security
::
validatePassword
(
$password
,
$hash
))
{
// all good, logging user in
}
else
{
// wrong password
}
```
Random data
-----------
Random data is useful in many cases. For example, when resetting a password via email you need to generate a token,
save it to database and send it via email to end user so he's able to prove that email belongs to him. It is very
important for this token to be truly unique else there will be a possibility to predict a value and reset another user's
password.
Yii security helper makes it as simple as:
```
php
$key
=
\yii\helpers\Security
::
generateRandomKey
();
```
Encryption and decryption
-------------------------
In order to encrypt data so only person knowing a secret passphrase or having a secret key will be able to decrypt it.
For example, we need to store some information in our database but we need to make sure only user knowing a secret code
can view it (even if database is leaked):
```php
// $data and $secretWord are from the form
$encryptedData = \yii\helpers\Security::encrypt($data, $secretWord);
// store $encryptedData to database
```
Then when user want to read it:
```
php
// $secretWord is from the form, $encryptedData is from database
$data
=
\yii\helpers\Security
::
decrypt
(
$encryptedData
,
$secretWord
);
```
Making sure data wasn't modified
--------------------------------
hashData()
validateData()
Securing Cookies
----------------
-
validation
-
httpOnly
\ No newline at end of file
extensions/twig/composer.json
View file @
f78a77df
...
...
@@ -20,7 +20,7 @@
"minimum-stability"
:
"dev"
,
"require"
:
{
"yiisoft/yii2"
:
"*"
,
"twig/twig"
:
"v1.13.
0
"
"twig/twig"
:
"v1.13.
2
"
},
"autoload"
:
{
"psr-0"
:
{
"yii
\\
twig"
:
""
}
...
...
framework/yii/assets.php
View file @
f78a77df
...
...
@@ -6,6 +6,6 @@ return array(
yii\validators\PunycodeAsset
::
className
(),
yii\validators\ValidationAsset
::
className
(),
yii\widgets\ActiveFormAsset
::
className
(),
yii\
widgets
\CaptchaAsset
::
className
(),
yii\
captcha
\CaptchaAsset
::
className
(),
yii\widgets\MaskedInputAsset
::
className
(),
);
framework/yii/assets/yii.captcha.js
View file @
f78a77df
/**
* Yii Captcha widget.
*
* This is the JavaScript widget used by the yii\
widgets
\Captcha widget.
* This is the JavaScript widget used by the yii\
captcha
\Captcha widget.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
...
...
framework/yii/base/Application.php
View file @
f78a77df
...
...
@@ -179,6 +179,16 @@ abstract class Application extends Module
}
}
/**
* Returns an ID that uniquely identifies this module among all modules within the current application.
* Since this is an application instance, it will always return an empty string.
* @return string the unique ID of the module.
*/
public
function
getUniqueId
()
{
return
''
;
}
/**
* Runs the application.
* This is the main entrance of an application.
...
...
@@ -475,6 +485,8 @@ abstract class Application extends Module
*/
public
function
handleFatalError
()
{
unset
(
$this
->
_memoryReserve
);
// load ErrorException manually here because autoloading them will not work
// when error occurs while autoloading a class
if
(
!
class_exists
(
'\\yii\\base\\Exception'
,
false
))
{
...
...
@@ -487,7 +499,6 @@ abstract class Application extends Module
$error
=
error_get_last
();
if
(
ErrorException
::
isFatalError
(
$error
))
{
unset
(
$this
->
_memoryReserve
);
$exception
=
new
ErrorException
(
$error
[
'message'
],
$error
[
'type'
],
$error
[
'type'
],
$error
[
'file'
],
$error
[
'line'
]);
// use error_log because it's too late to use Yii log
error_log
(
$exception
);
...
...
framework/yii/base/Component.php
View file @
f78a77df
...
...
@@ -220,19 +220,19 @@ class Component extends Object
*
* - the class has a getter or setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkBehavior whether to treat behaviors' properties as properties of this component
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehavior
s
whether to treat behaviors' properties as properties of this component
* @return boolean whether the property is defined
* @see canGetProperty
* @see canSetProperty
*/
public
function
hasProperty
(
$name
,
$checkVar
=
true
,
$checkBehavior
=
true
)
public
function
hasProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
return
$this
->
canGetProperty
(
$name
,
$checkVar
,
$checkBehavior
)
||
$this
->
canSetProperty
(
$name
,
$checkVar
,
$checkBehavior
);
return
$this
->
canGetProperty
(
$name
,
$checkVar
s
,
$checkBehaviors
)
||
$this
->
canSetProperty
(
$name
,
false
,
$checkBehaviors
);
}
/**
...
...
@@ -241,23 +241,23 @@ class Component extends Object
*
* - the class has a getter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a readable property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a readable property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkBehavior whether to treat behaviors' properties as properties of this component
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehavior
s
whether to treat behaviors' properties as properties of this component
* @return boolean whether the property can be read
* @see canSetProperty
*/
public
function
canGetProperty
(
$name
,
$checkVar
=
true
,
$checkBehavior
=
true
)
public
function
canGetProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
if
(
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
))
{
if
(
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
))
{
return
true
;
}
else
{
}
else
if
(
$checkBehaviors
)
{
$this
->
ensureBehaviors
();
foreach
(
$this
->
_behaviors
as
$behavior
)
{
if
(
$behavior
->
canGetProperty
(
$name
,
$checkVar
))
{
if
(
$behavior
->
canGetProperty
(
$name
,
$checkVar
s
))
{
return
true
;
}
}
...
...
@@ -271,23 +271,23 @@ class Component extends Object
*
* - the class has a setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a writable property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a writable property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkBehavior whether to treat behaviors' properties as properties of this component
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehavior
s
whether to treat behaviors' properties as properties of this component
* @return boolean whether the property can be written
* @see canGetProperty
*/
public
function
canSetProperty
(
$name
,
$checkVar
=
true
,
$checkBehavior
=
true
)
public
function
canSetProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
if
(
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
))
{
if
(
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
))
{
return
true
;
}
else
{
}
else
if
(
$checkBehaviors
)
{
$this
->
ensureBehaviors
();
foreach
(
$this
->
_behaviors
as
$behavior
)
{
if
(
$behavior
->
canSetProperty
(
$name
,
$checkVar
))
{
if
(
$behavior
->
canSetProperty
(
$name
,
$checkVar
s
))
{
return
true
;
}
}
...
...
framework/yii/base/ErrorHandler.php
View file @
f78a77df
...
...
@@ -192,11 +192,16 @@ class ErrorHandler extends Component
*/
public
function
renderFile
(
$_file_
,
$_params_
)
{
ob_start
();
ob_implicit_flush
(
false
);
extract
(
$_params_
,
EXTR_OVERWRITE
);
require
(
Yii
::
getAlias
(
$_file_
));
return
ob_get_clean
();
$_params_
[
'handler'
]
=
$this
;
if
(
$this
->
exception
instanceof
ErrorException
)
{
ob_start
();
ob_implicit_flush
(
false
);
extract
(
$_params_
,
EXTR_OVERWRITE
);
require
(
Yii
::
getAlias
(
$_file_
));
return
ob_get_clean
();
}
else
{
return
Yii
::
$app
->
getView
()
->
renderFile
(
$_file_
,
$_params_
,
$this
);
}
}
/**
...
...
framework/yii/base/Formatter.php
View file @
f78a77df
...
...
@@ -71,22 +71,36 @@ class Formatter extends Component
}
/**
* Formats the value based on the given type.
* Formats the value based on the given
format
type.
* This method will call one of the "as" methods available in this class to do the formatting.
* For type "xyz", the method "asXyz" will be used. For example, if the
type
is "html",
* then [[asHtml()]] will be used.
Type
names are case insensitive.
* For type "xyz", the method "asXyz" will be used. For example, if the
format
is "html",
* then [[asHtml()]] will be used.
Format
names are case insensitive.
* @param mixed $value the value to be formatted
* @param string $type the type of the value, e.g., "html", "text".
* @param string|array $format the format of the value, e.g., "html", "text". To specify additional
* parameters of the formatting method, you may use an array. The first element of the array
* specifies the format name, while the rest of the elements will be used as the parameters to the formatting
* method. For example, a format of `array('date', 'Y-m-d')` will cause the invocation of `asDate($value, 'Y-m-d')`.
* @return string the formatting result
* @throws InvalidParamException if the type is not supported by this class.
*/
public
function
format
(
$value
,
$
type
)
public
function
format
(
$value
,
$
format
)
{
$method
=
'as'
.
$type
;
if
(
is_array
(
$format
))
{
if
(
!
isset
(
$format
[
0
]))
{
throw
new
InvalidParamException
(
'The $format array must contain at least one element.'
);
}
$f
=
$format
[
0
];
$format
[
0
]
=
$value
;
$params
=
$format
;
$format
=
$f
;
}
else
{
$params
=
array
(
$value
);
}
$method
=
'as'
.
$format
;
if
(
method_exists
(
$this
,
$method
))
{
return
$this
->
$method
(
$value
);
return
call_user_func_array
(
array
(
$this
,
$method
),
$params
);
}
else
{
throw
new
InvalidParamException
(
"Unknown type:
$
type
"
);
throw
new
InvalidParamException
(
"Unknown type:
$
format
"
);
}
}
...
...
framework/yii/base/Model.php
View file @
f78a77df
...
...
@@ -117,8 +117,8 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
* array('password', 'compare', 'compareAttribute' => 'password2', 'on' => 'register'),
* // an inline validator defined via the "authenticate()" method in the model class
* array('password', 'authenticate', 'on' => 'login'),
* // a validator of class "
Captcha
Validator"
* array('
captcha', 'Captcha
Validator'),
* // a validator of class "
DateRange
Validator"
* array('
dateRange', 'DateRange
Validator'),
* );
* ~~~
*
...
...
framework/yii/base/Module.php
View file @
f78a77df
...
...
@@ -192,13 +192,7 @@ abstract class Module extends Component
*/
public
function
getUniqueId
()
{
if
(
$this
instanceof
Application
)
{
return
''
;
}
elseif
(
$this
->
module
)
{
return
ltrim
(
$this
->
module
->
getUniqueId
()
.
'/'
.
$this
->
id
,
'/'
);
}
else
{
return
$this
->
id
;
}
return
$this
->
module
?
ltrim
(
$this
->
module
->
getUniqueId
()
.
'/'
.
$this
->
id
,
'/'
)
:
$this
->
id
;
}
/**
...
...
framework/yii/base/Object.php
View file @
f78a77df
...
...
@@ -170,17 +170,17 @@ class Object implements Arrayable
*
* - the class has a getter or setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property is defined
* @see canGetProperty
* @see canSetProperty
*/
public
function
hasProperty
(
$name
,
$checkVar
=
true
)
public
function
hasProperty
(
$name
,
$checkVar
s
=
true
)
{
return
$this
->
canGetProperty
(
$name
,
$checkVar
)
||
$this
->
canSetProperty
(
$name
,
false
);
return
$this
->
canGetProperty
(
$name
,
$checkVar
s
)
||
$this
->
canSetProperty
(
$name
,
false
);
}
/**
...
...
@@ -189,16 +189,16 @@ class Object implements Arrayable
*
* - the class has a getter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property can be read
* @see canSetProperty
*/
public
function
canGetProperty
(
$name
,
$checkVar
=
true
)
public
function
canGetProperty
(
$name
,
$checkVar
s
=
true
)
{
return
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
);
return
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
);
}
/**
...
...
@@ -207,16 +207,16 @@ class Object implements Arrayable
*
* - the class has a setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property can be written
* @see canGetProperty
*/
public
function
canSetProperty
(
$name
,
$checkVar
=
true
)
public
function
canSetProperty
(
$name
,
$checkVar
s
=
true
)
{
return
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
);
return
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
);
}
/**
...
...
framework/yii/bootstrap/Carousel.php
View file @
f78a77df
...
...
@@ -55,7 +55,7 @@ class Carousel extends Widget
* // required, slide content (HTML), such as an image tag
* 'content' => '<img src="http://twitter.github.io/bootstrap/assets/img/bootstrap-mdo-sfmoma-01.jpg"/>',
* // optional, the caption (HTML) of the slide
* 'caption'=> '<h4>This is title</h4><p>This is the caption text</p>',
* 'caption'
=> '<h4>This is title</h4><p>This is the caption text</p>',
* // optional the HTML attributes of the slide container
* 'options' => array(),
* )
...
...
framework/yii/bootstrap/Collapse.php
View file @
f78a77df
...
...
@@ -23,7 +23,7 @@ use yii\helpers\Html;
* 'Collapsible Group Item #1' => array(
* 'content' => 'Anim pariatur cliche...',
* // open its content by default
* 'contentOptions' => array('class'
=>
'in')
* 'contentOptions' => array('class'
=>
'in')
* ),
* // another group item
* 'Collapsible Group Item #2' => array(
...
...
@@ -51,9 +51,9 @@ class Collapse extends Widget
* // required, the content (HTML) of the group
* 'content' => 'Anim pariatur cliche...',
* // optional the HTML attributes of the content group
* 'contentOptions'=> array(),
* 'contentOptions'
=> array(),
* // optional the HTML attributes of the group
* 'options'=> array(),
* 'options'
=> array(),
* )
* ```
*/
...
...
framework/yii/bootstrap/Nav.php
View file @
f78a77df
...
...
@@ -136,6 +136,7 @@ class Nav extends Widget
if
(
is_array
(
$items
))
{
$items
=
Dropdown
::
widget
(
array
(
'items'
=>
$items
,
'encodeLabels'
=>
$this
->
encodeLabels
,
'clientOptions'
=>
false
,
));
}
...
...
framework/yii/bootstrap/NavBar.php
View file @
f78a77df
...
...
@@ -87,7 +87,7 @@ class NavBar extends Widget
* // optional, the menu item class type of the widget to render. Defaults to "Nav" widget.
* 'class' => 'Menu item class type',
* // required, the configuration options of the widget.
* 'options'=> array(...),
* 'options'
=> array(...),
* ),
* // optionally, you can pass a string
* '<form class="navbar-search pull-left" action="">' .
...
...
framework/yii/bootstrap/Progress.php
View file @
f78a77df
...
...
@@ -47,7 +47,7 @@ use yii\helpers\Html;
* echo Progress::widget(array(
* 'bars' => array(
* array('percent' => 30, 'options' => array('class' => 'bar-danger')),
* array('percent' => 30, 'label'
=>
'test', 'options' => array('class' => 'bar-success')),
* array('percent' => 30, 'label'
=>
'test', 'options' => array('class' => 'bar-success')),
* array('percent' => 35, 'options' => array('class' => 'bar-warning'))
* )
* ));
...
...
framework/yii/bootstrap/Tabs.php
View file @
f78a77df
...
...
@@ -28,7 +28,7 @@ use yii\helpers\Html;
* 'label' => 'Two',
* 'content' => 'Anim pariatur cliche...',
* 'headerOptions' => array(...),
* 'options' => array('id'
=>
'myveryownID'),
* 'options' => array('id'
=>
'myveryownID'),
* ),
* array(
* 'label' => 'Dropdown',
...
...
framework/yii/
widgets
/Captcha.php
→
framework/yii/
captcha
/Captcha.php
View file @
f78a77df
...
...
@@ -5,13 +5,14 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\
widgets
;
namespace
yii\
captcha
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
use
yii\web\CaptchaAction
;
use
yii\widgets\InputWidget
;
/**
* Captcha renders a CAPTCHA image and an input field that takes user-entered verification code.
...
...
framework/yii/
web
/CaptchaAction.php
→
framework/yii/
captcha
/CaptchaAction.php
View file @
f78a77df
...
...
@@ -5,12 +5,11 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\
web
;
namespace
yii\
captcha
;
use
Yii
;
use
yii\base\Action
;
use
yii\base\InvalidConfigException
;
use
yii\widgets\Captcha
;
/**
* CaptchaAction renders a CAPTCHA image.
...
...
@@ -85,7 +84,7 @@ class CaptchaAction extends Action
/**
* @var string the TrueType font file. This can be either a file path or path alias.
*/
public
$fontFile
=
'@yii/
web
/SpicyRice.ttf'
;
public
$fontFile
=
'@yii/
captcha
/SpicyRice.ttf'
;
/**
* @var string the fixed verification code. When this property is set,
* [[getVerifyCode()]] will always return the value of this property.
...
...
@@ -116,12 +115,14 @@ class CaptchaAction extends Action
if
(
isset
(
$_GET
[
self
::
REFRESH_GET_VAR
]))
{
// AJAX request for regenerating code
$code
=
$this
->
getVerifyCode
(
true
);
/** @var \yii\web\Controller $controller */
$controller
=
$this
->
controller
;
return
json_encode
(
array
(
'hash1'
=>
$this
->
generateValidationHash
(
$code
),
'hash2'
=>
$this
->
generateValidationHash
(
strtolower
(
$code
)),
// we add a random 'v' parameter so that FireFox can refresh the image
// when src attribute of image tag is changed
'url'
=>
$
this
->
controller
->
createUrl
(
$this
->
id
,
array
(
'v'
=>
uniqid
())),
'url'
=>
$controller
->
createUrl
(
$this
->
id
,
array
(
'v'
=>
uniqid
())),
));
}
else
{
$this
->
setHttpHeaders
();
...
...
@@ -153,7 +154,7 @@ class CaptchaAction extends Action
return
$this
->
fixedVerifyCode
;
}
$session
=
Yii
::
$app
->
session
;
$session
=
Yii
::
$app
->
getSession
()
;
$session
->
open
();
$name
=
$this
->
getSessionKey
();
if
(
$session
[
$name
]
===
null
||
$regenerate
)
{
...
...
@@ -189,15 +190,15 @@ class CaptchaAction extends Action
*/
protected
function
generateVerifyCode
()
{
if
(
$this
->
minLength
>
$this
->
maxLength
)
{
$this
->
maxLength
=
$this
->
minLength
;
}
if
(
$this
->
minLength
<
3
)
{
$this
->
minLength
=
3
;
}
if
(
$this
->
maxLength
>
20
)
{
$this
->
maxLength
=
20
;
}
if
(
$this
->
minLength
>
$this
->
maxLength
)
{
$this
->
maxLength
=
$this
->
minLength
;
}
$length
=
mt_rand
(
$this
->
minLength
,
$this
->
maxLength
);
$letters
=
'bcdfghjklmnpqrstvwxyz'
;
...
...
framework/yii/
widgets
/CaptchaAsset.php
→
framework/yii/
captcha
/CaptchaAsset.php
View file @
f78a77df
...
...
@@ -5,7 +5,8 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets
;
namespace
yii\captcha
;
use
yii\web\AssetBundle
;
/**
...
...
framework/yii/
validators
/CaptchaValidator.php
→
framework/yii/
captcha
/CaptchaValidator.php
View file @
f78a77df
...
...
@@ -5,11 +5,13 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\
validators
;
namespace
yii\
captcha
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
use
yii\validators\ValidationAsset
;
use
yii\validators\Validator
;
/**
* CaptchaValidator validates that the attribute value is the same as the verification code displayed in the CAPTCHA.
...
...
@@ -74,7 +76,7 @@ class CaptchaValidator extends Validator
/**
* Returns the CAPTCHA action object.
* @throws InvalidConfigException
* @return \yii\
web
\CaptchaAction the action object
* @return \yii\
captcha
\CaptchaAction the action object
*/
public
function
getCaptchaAction
()
{
...
...
framework/yii/
web
/SpicyRice.md
→
framework/yii/
captcha
/SpicyRice.md
View file @
f78a77df
File moved
framework/yii/
web
/SpicyRice.ttf
→
framework/yii/
captcha
/SpicyRice.ttf
View file @
f78a77df
File moved
framework/yii/classes.php
View file @
f78a77df
...
...
@@ -91,6 +91,10 @@ return array(
'yii\caching\WinCache'
=>
YII_PATH
.
'/caching/WinCache.php'
,
'yii\caching\XCache'
=>
YII_PATH
.
'/caching/XCache.php'
,
'yii\caching\ZendDataCache'
=>
YII_PATH
.
'/caching/ZendDataCache.php'
,
'yii\captcha\Captcha'
=>
YII_PATH
.
'/captcha/Captcha.php'
,
'yii\captcha\CaptchaAction'
=>
YII_PATH
.
'/captcha/CaptchaAction.php'
,
'yii\captcha\CaptchaAsset'
=>
YII_PATH
.
'/captcha/CaptchaAsset.php'
,
'yii\captcha\CaptchaValidator'
=>
YII_PATH
.
'/captcha/CaptchaValidator.php'
,
'yii\data\ActiveDataProvider'
=>
YII_PATH
.
'/data/ActiveDataProvider.php'
,
'yii\data\ArrayDataProvider'
=>
YII_PATH
.
'/data/ArrayDataProvider.php'
,
'yii\data\DataProvider'
=>
YII_PATH
.
'/data/DataProvider.php'
,
...
...
@@ -167,7 +171,6 @@ return array(
'yii\rbac\PhpManager'
=>
YII_PATH
.
'/rbac/PhpManager.php'
,
'yii\requirements\YiiRequirementChecker'
=>
YII_PATH
.
'/requirements/YiiRequirementChecker.php'
,
'yii\validators\BooleanValidator'
=>
YII_PATH
.
'/validators/BooleanValidator.php'
,
'yii\validators\CaptchaValidator'
=>
YII_PATH
.
'/validators/CaptchaValidator.php'
,
'yii\validators\CompareValidator'
=>
YII_PATH
.
'/validators/CompareValidator.php'
,
'yii\validators\DateValidator'
=>
YII_PATH
.
'/validators/DateValidator.php'
,
'yii\validators\DefaultValueValidator'
=>
YII_PATH
.
'/validators/DefaultValueValidator.php'
,
...
...
@@ -193,7 +196,6 @@ return array(
'yii\web\AssetConverter'
=>
YII_PATH
.
'/web/AssetConverter.php'
,
'yii\web\AssetManager'
=>
YII_PATH
.
'/web/AssetManager.php'
,
'yii\web\CacheSession'
=>
YII_PATH
.
'/web/CacheSession.php'
,
'yii\web\CaptchaAction'
=>
YII_PATH
.
'/web/CaptchaAction.php'
,
'yii\web\Controller'
=>
YII_PATH
.
'/web/Controller.php'
,
'yii\web\Cookie'
=>
YII_PATH
.
'/web/Cookie.php'
,
'yii\web\CookieCollection'
=>
YII_PATH
.
'/web/CookieCollection.php'
,
...
...
@@ -225,14 +227,18 @@ return array(
'yii\widgets\ActiveFormAsset'
=>
YII_PATH
.
'/widgets/ActiveFormAsset.php'
,
'yii\widgets\Block'
=>
YII_PATH
.
'/widgets/Block.php'
,
'yii\widgets\Breadcrumbs'
=>
YII_PATH
.
'/widgets/Breadcrumbs.php'
,
'yii\widgets\Captcha'
=>
YII_PATH
.
'/widgets/Captcha.php'
,
'yii\widgets\CaptchaAsset'
=>
YII_PATH
.
'/widgets/CaptchaAsset.php'
,
'yii\widgets\ContentDecorator'
=>
YII_PATH
.
'/widgets/ContentDecorator.php'
,
'yii\widgets\DetailView'
=>
YII_PATH
.
'/widgets/DetailView.php'
,
'yii\widgets\FragmentCache'
=>
YII_PATH
.
'/widgets/FragmentCache.php'
,
'yii\widgets\grid\CheckboxColumn'
=>
YII_PATH
.
'/widgets/grid/CheckboxColumn.php'
,
'yii\widgets\grid\Column'
=>
YII_PATH
.
'/widgets/grid/Column.php'
,
'yii\widgets\grid\DataColumn'
=>
YII_PATH
.
'/widgets/grid/DataColumn.php'
,
'yii\widgets\GridView'
=>
YII_PATH
.
'/widgets/GridView.php'
,
'yii\widgets\InputWidget'
=>
YII_PATH
.
'/widgets/InputWidget.php'
,
'yii\widgets\LinkPager'
=>
YII_PATH
.
'/widgets/LinkPager.php'
,
'yii\widgets\ListPager'
=>
YII_PATH
.
'/widgets/ListPager.php'
,
'yii\widgets\LinkSorter'
=>
YII_PATH
.
'/widgets/LinkSorter.php'
,
'yii\widgets\ListView'
=>
YII_PATH
.
'/widgets/ListView.php'
,
'yii\widgets\ListViewBase'
=>
YII_PATH
.
'/widgets/ListViewBase.php'
,
'yii\widgets\MaskedInput'
=>
YII_PATH
.
'/widgets/MaskedInput.php'
,
'yii\widgets\MaskedInputAsset'
=>
YII_PATH
.
'/widgets/MaskedInputAsset.php'
,
'yii\widgets\Menu'
=>
YII_PATH
.
'/widgets/Menu.php'
,
...
...
framework/yii/console/controllers/HelpController.php
View file @
f78a77df
...
...
@@ -129,7 +129,7 @@ class HelpController extends Controller
$files
=
scandir
(
$module
->
getControllerPath
());
foreach
(
$files
as
$file
)
{
if
(
strcmp
(
substr
(
$file
,
-
14
),
'Controller.php'
)
===
0
)
{
$commands
[]
=
$prefix
.
lcfirst
(
substr
(
basename
(
$file
),
0
,
-
14
));
$commands
[]
=
$prefix
.
Inflector
::
camel2id
(
substr
(
basename
(
$file
),
0
,
-
14
));
}
}
...
...
framework/yii/data/ActiveDataProvider.php
View file @
f78a77df
...
...
@@ -29,7 +29,7 @@ use yii\db\Connection;
* ));
*
* // get the posts in the current page
* $posts = $provider->get
Item
s();
* $posts = $provider->get
Model
s();
* ~~~
*
* And the following example shows how to use ActiveDataProvider without ActiveRecord:
...
...
@@ -44,7 +44,7 @@ use yii\db\Connection;
* ));
*
* // get the posts in the current page
* $posts = $provider->get
Item
s();
* $posts = $provider->get
Model
s();
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -53,18 +53,18 @@ use yii\db\Connection;
class
ActiveDataProvider
extends
DataProvider
{
/**
* @var Query the query that is used to fetch data
item
s and [[totalCount]]
* @var Query the query that is used to fetch data
model
s and [[totalCount]]
* if it is not explicitly set.
*/
public
$query
;
/**
* @var string|callable the column that is used as the key of the data
item
s.
* This can be either a column name, or a callable that returns the key value of a given data
item
.
* @var string|callable the column that is used as the key of the data
model
s.
* This can be either a column name, or a callable that returns the key value of a given data
model
.
*
* If this is not set, the following rules will be used to determine the keys of the data
item
s:
* If this is not set, the following rules will be used to determine the keys of the data
model
s:
*
* - If [[query]] is an [[ActiveQuery]] instance, the primary keys of [[ActiveQuery::modelClass]] will be used.
* - Otherwise, the keys of the [[
item
s]] array will be used.
* - Otherwise, the keys of the [[
model
s]] array will be used.
*
* @see getKeys()
*/
...
...
@@ -75,9 +75,9 @@ class ActiveDataProvider extends DataProvider
*/
public
$db
;
private
$_
item
s
;
private
$_
model
s
;
private
$_keys
;
private
$_
c
ount
;
private
$_
totalC
ount
;
/**
* Initializes the DbCache component.
...
...
@@ -96,59 +96,55 @@ class ActiveDataProvider extends DataProvider
}
/**
* Returns the number of data
item
s in the current page.
* This is equivalent to `count($provider->
item
s)`.
* Returns the number of data
model
s in the current page.
* This is equivalent to `count($provider->
model
s)`.
* When [[pagination]] is false, this is the same as [[totalCount]].
* @param boolean $refresh whether to recalculate the item count. If true,
* this will cause re-fetching of [[items]].
* @return integer the number of data items in the current page.
* @return integer the number of data models in the current page.
*/
public
function
getCount
(
$refresh
=
false
)
public
function
getCount
()
{
return
count
(
$this
->
get
Items
(
$refresh
));
return
count
(
$this
->
get
Models
(
));
}
/**
* Returns the total number of data
item
s.
* Returns the total number of data
model
s.
* When [[pagination]] is false, this returns the same value as [[count]].
* If [[totalCount]] is not explicitly set, it will be calculated
* using [[query]] with a COUNT query.
* @param boolean $refresh whether to recalculate the item count
* @return integer total number of possible data items.
* @return integer total number of possible data models.
* @throws InvalidConfigException
*/
public
function
getTotalCount
(
$refresh
=
false
)
public
function
getTotalCount
()
{
if
(
$this
->
getPagination
()
===
false
)
{
return
$this
->
getCount
(
$refresh
);
}
elseif
(
$this
->
_
count
===
null
||
$refresh
)
{
return
$this
->
getCount
();
}
elseif
(
$this
->
_
totalCount
===
null
)
{
if
(
!
$this
->
query
instanceof
Query
)
{
throw
new
InvalidConfigException
(
'The "query" property must be an instance of Query or its subclass.'
);
}
$query
=
clone
$this
->
query
;
$this
->
_
c
ount
=
$query
->
limit
(
-
1
)
->
offset
(
-
1
)
->
count
(
'*'
,
$this
->
db
);
$this
->
_
totalC
ount
=
$query
->
limit
(
-
1
)
->
offset
(
-
1
)
->
count
(
'*'
,
$this
->
db
);
}
return
$this
->
_
c
ount
;
return
$this
->
_
totalC
ount
;
}
/**
* Sets the total number of data
item
s.
* @param integer $value the total number of data
item
s.
* Sets the total number of data
model
s.
* @param integer $value the total number of data
model
s.
*/
public
function
setTotalCount
(
$value
)
{
$this
->
_
c
ount
=
$value
;
$this
->
_
totalC
ount
=
$value
;
}
/**
* Returns the data items in the current page.
* @param boolean $refresh whether to re-fetch the data items.
* @return array the list of data items in the current page.
* @throws InvalidConfigException
* Returns the data models in the current page.
* @return array the list of data models in the current page.
* @throws InvalidConfigException if [[query]] is not set or invalid.
*/
public
function
get
Items
(
$refresh
=
false
)
public
function
get
Models
(
)
{
if
(
$this
->
_
items
===
null
||
$refresh
)
{
if
(
$this
->
_
models
===
null
)
{
if
(
!
$this
->
query
instanceof
Query
)
{
throw
new
InvalidConfigException
(
'The "query" property must be an instance of Query or its subclass.'
);
}
...
...
@@ -159,28 +155,27 @@ class ActiveDataProvider extends DataProvider
if
((
$sort
=
$this
->
getSort
())
!==
false
)
{
$this
->
query
->
orderBy
(
$sort
->
getOrders
());
}
$this
->
_
item
s
=
$this
->
query
->
all
(
$this
->
db
);
$this
->
_
model
s
=
$this
->
query
->
all
(
$this
->
db
);
}
return
$this
->
_
item
s
;
return
$this
->
_
model
s
;
}
/**
* Returns the key values associated with the data items.
* @param boolean $refresh whether to re-fetch the data items and re-calculate the keys
* @return array the list of key values corresponding to [[items]]. Each data item in [[items]]
* Returns the key values associated with the data models.
* @return array the list of key values corresponding to [[models]]. Each data model in [[models]]
* is uniquely identified by the corresponding key value in this array.
*/
public
function
getKeys
(
$refresh
=
false
)
public
function
getKeys
()
{
if
(
$this
->
_keys
===
null
||
$refresh
)
{
if
(
$this
->
_keys
===
null
)
{
$this
->
_keys
=
array
();
$
items
=
$this
->
getItems
(
$refresh
);
$
models
=
$this
->
getModels
(
);
if
(
$this
->
key
!==
null
)
{
foreach
(
$
items
as
$item
)
{
foreach
(
$
models
as
$model
)
{
if
(
is_string
(
$this
->
key
))
{
$this
->
_keys
[]
=
$
item
[
$this
->
key
];
$this
->
_keys
[]
=
$
model
[
$this
->
key
];
}
else
{
$this
->
_keys
[]
=
call_user_func
(
$this
->
key
,
$
item
);
$this
->
_keys
[]
=
call_user_func
(
$this
->
key
,
$
model
);
}
}
}
elseif
(
$this
->
query
instanceof
ActiveQuery
)
{
...
...
@@ -189,22 +184,34 @@ class ActiveDataProvider extends DataProvider
$pks
=
$class
::
primaryKey
();
if
(
count
(
$pks
)
===
1
)
{
$pk
=
$pks
[
0
];
foreach
(
$
items
as
$item
)
{
$this
->
_keys
[]
=
$
item
[
$pk
];
foreach
(
$
models
as
$model
)
{
$this
->
_keys
[]
=
$
model
[
$pk
];
}
}
else
{
foreach
(
$
items
as
$item
)
{
foreach
(
$
models
as
$model
)
{
$keys
=
array
();
foreach
(
$pks
as
$pk
)
{
$keys
[]
=
$
item
[
$pk
];
$keys
[]
=
$
model
[
$pk
];
}
$this
->
_keys
[]
=
json_encode
(
$keys
);
}
}
}
else
{
$this
->
_keys
=
array_keys
(
$
item
s
);
$this
->
_keys
=
array_keys
(
$
model
s
);
}
}
return
$this
->
_keys
;
}
/**
* Refreshes the data provider.
* After calling this method, if [[getModels()]], [[getKeys()]] or [[getTotalCount()]] is called again,
* they will re-execute the query and return the latest data available.
*/
public
function
refresh
()
{
$this
->
_models
=
null
;
$this
->
_totalCount
=
null
;
$this
->
_keys
=
null
;
}
}
framework/yii/data/ArrayDataProvider.php
View file @
f78a77df
...
...
@@ -13,25 +13,25 @@ use yii\helpers\ArrayHelper;
/**
* ArrayDataProvider implements a data provider based on a data array.
*
* The [[all
Items]] property contains all data item
s that may be sorted and/or paginated.
* The [[all
Models]] property contains all data model
s that may be sorted and/or paginated.
* ArrayDataProvider will provide the data after sorting and/or pagination.
* You may configure the [[sort]] and [[pagination]] properties to
* customize the sorting and pagination behaviors.
*
* Elements in the [[all
Item
s]] array may be either objects (e.g. model objects)
* Elements in the [[all
Model
s]] array may be either objects (e.g. model objects)
* or associative arrays (e.g. query results of DAO).
* Make sure to set the [[key]] property to the name of the field that uniquely
* identifies a data record or false if you do not have such a field.
*
* Compared to [[ActiveDataProvider]], ArrayDataProvider could be less efficient
* because it needs to have [[all
Item
s]] ready.
* because it needs to have [[all
Model
s]] ready.
*
* ArrayDataProvider may be used in the following way:
*
* ~~~
* $query = new Query;
* $provider = new ArrayDataProvider(array(
* 'all
Item
s' => $query->from('tbl_post')->all(),
* 'all
Model
s' => $query->from('tbl_post')->all(),
* 'sort' => array(
* 'attributes' => array(
* 'id', 'username', 'email',
...
...
@@ -42,7 +42,7 @@ use yii\helpers\ArrayHelper;
* ),
* ));
* // get the posts in the current page
* $posts = $provider->get
Item
s();
* $posts = $provider->get
Model
s();
* ~~~
*
* Note: if you want to use the sorting feature, you must configure the [[sort]] property
...
...
@@ -54,116 +54,110 @@ use yii\helpers\ArrayHelper;
class
ArrayDataProvider
extends
DataProvider
{
/**
* @var string|callable the column that is used as the key of the data
item
s.
* This can be either a column name, or a callable that returns the key value of a given data
item
.
* If this is not set, the index of the [[
item
s]] array will be used.
* @var string|callable the column that is used as the key of the data
model
s.
* This can be either a column name, or a callable that returns the key value of a given data
model
.
* If this is not set, the index of the [[
model
s]] array will be used.
* @see getKeys()
*/
public
$key
;
/**
* @var array the data that is not paginated or sorted. When pagination is enabled,
* this property usually contains more elements than [[
item
s]].
* this property usually contains more elements than [[
model
s]].
* The array elements must use zero-based integer keys.
*/
public
$all
Item
s
;
public
$all
Model
s
;
private
$_totalCount
;
/**
* Returns the total number of data items.
* @return integer total number of possible data items.
* @throws InvalidConfigException
* Returns the total number of data models.
* @return integer total number of possible data models.
*/
public
function
getTotalCount
()
{
if
(
$this
->
getPagination
()
===
false
)
{
return
$this
->
getCount
();
}
elseif
(
$this
->
_totalCount
===
null
)
{
if
(
$this
->
allItems
!==
null
)
{
$this
->
_totalCount
=
count
(
$this
->
allItems
);
}
else
{
throw
new
InvalidConfigException
(
'Unable to determine total item count: either "allItems" or "totalCount" must be set.'
);
}
$this
->
_totalCount
=
count
(
$this
->
allModels
);
}
return
$this
->
_totalCount
;
}
/**
* Sets the total number of data
item
s.
* @param integer $value the total number of data
item
s.
* Sets the total number of data
model
s.
* @param integer $value the total number of data
model
s.
*/
public
function
setTotalCount
(
$value
)
{
$this
->
_totalCount
=
$value
;
}
private
$_
item
s
;
private
$_
model
s
;
/**
* Returns the data items in the current page.
* @return array the list of data items in the current page.
* @throws InvalidConfigException
* Returns the data models in the current page.
* @return array the list of data models in the current page.
*/
public
function
get
Item
s
()
public
function
get
Model
s
()
{
if
(
$this
->
_
item
s
===
null
)
{
if
((
$
items
=
$this
->
allItem
s
)
===
null
)
{
throw
new
InvalidConfigException
(
'Either "items" or "allItems" must be set.'
);
if
(
$this
->
_
model
s
===
null
)
{
if
((
$
models
=
$this
->
allModel
s
)
===
null
)
{
return
array
(
);
}
if
((
$sort
=
$this
->
getSort
())
!==
false
)
{
$
items
=
$this
->
sortItems
(
$item
s
,
$sort
);
$
models
=
$this
->
sortModels
(
$model
s
,
$sort
);
}
if
((
$pagination
=
$this
->
getPagination
())
!==
false
)
{
$pagination
->
totalCount
=
$this
->
getTotalCount
();
$
items
=
array_slice
(
$item
s
,
$pagination
->
getOffset
(),
$pagination
->
getLimit
());
$
models
=
array_slice
(
$model
s
,
$pagination
->
getOffset
(),
$pagination
->
getLimit
());
}
$this
->
_
items
=
$item
s
;
$this
->
_
models
=
$model
s
;
}
return
$this
->
_
item
s
;
return
$this
->
_
model
s
;
}
/**
* Sets the data
item
s in the current page.
* @param array $
items the item
s in the current page
* Sets the data
model
s in the current page.
* @param array $
models the model
s in the current page
*/
public
function
set
Items
(
$item
s
)
public
function
set
Models
(
$model
s
)
{
$this
->
_
items
=
$item
s
;
$this
->
_
models
=
$model
s
;
}
private
$_keys
;
/**
* Returns the key values associated with the data
item
s.
* @return array the list of key values corresponding to [[
items]]. Each data item in [[item
s]]
* Returns the key values associated with the data
model
s.
* @return array the list of key values corresponding to [[
models]]. Each data model in [[model
s]]
* is uniquely identified by the corresponding key value in this array.
*/
public
function
getKeys
()
{
if
(
$this
->
_keys
===
null
)
{
$this
->
_keys
=
array
();
$
items
=
$this
->
getItem
s
();
$
models
=
$this
->
getModel
s
();
if
(
$this
->
key
!==
null
)
{
foreach
(
$
items
as
$item
)
{
foreach
(
$
models
as
$model
)
{
if
(
is_string
(
$this
->
key
))
{
$this
->
_keys
[]
=
$
item
[
$this
->
key
];
$this
->
_keys
[]
=
$
model
[
$this
->
key
];
}
else
{
$this
->
_keys
[]
=
call_user_func
(
$this
->
key
,
$
item
);
$this
->
_keys
[]
=
call_user_func
(
$this
->
key
,
$
model
);
}
}
}
else
{
$this
->
_keys
=
array_keys
(
$
item
s
);
$this
->
_keys
=
array_keys
(
$
model
s
);
}
}
return
$this
->
_keys
;
}
/**
* Sets the key values associated with the data
item
s.
* @param array $keys the list of key values corresponding to [[
item
s]].
* Sets the key values associated with the data
model
s.
* @param array $keys the list of key values corresponding to [[
model
s]].
*/
public
function
setKeys
(
$keys
)
{
...
...
@@ -171,17 +165,17 @@ class ArrayDataProvider extends DataProvider
}
/**
* Sorts the data
item
s according to the given sort definition
* @param array $
items the item
s to be sorted
* Sorts the data
model
s according to the given sort definition
* @param array $
models the model
s to be sorted
* @param Sort $sort the sort definition
* @return array the sorted data
item
s
* @return array the sorted data
model
s
*/
protected
function
sort
Items
(
$item
s
,
$sort
)
protected
function
sort
Models
(
$model
s
,
$sort
)
{
$orders
=
$sort
->
getOrders
();
if
(
!
empty
(
$orders
))
{
ArrayHelper
::
multisort
(
$
item
s
,
array_keys
(
$orders
),
array_values
(
$orders
));
ArrayHelper
::
multisort
(
$
model
s
,
array_keys
(
$orders
),
array_values
(
$orders
));
}
return
$
item
s
;
return
$
model
s
;
}
}
framework/yii/data/DataProvider.php
View file @
f78a77df
...
...
@@ -118,11 +118,11 @@ abstract class DataProvider extends Component implements IDataProvider
}
/**
* Returns the number of data
item
s in the current page.
* @return integer the number of data
item
s in the current page.
* Returns the number of data
model
s in the current page.
* @return integer the number of data
model
s in the current page.
*/
public
function
getCount
()
{
return
count
(
$this
->
get
Item
s
());
return
count
(
$this
->
get
Model
s
());
}
}
framework/yii/data/IDataProvider.php
View file @
f78a77df
...
...
@@ -19,29 +19,29 @@ namespace yii\data;
interface
IDataProvider
{
/**
* Returns the number of data
item
s in the current page.
* This is equivalent to `count($provider->get
Item
s())`.
* Returns the number of data
model
s in the current page.
* This is equivalent to `count($provider->get
Model
s())`.
* When [[pagination]] is false, this is the same as [[totalCount]].
* @return integer the number of data
item
s in the current page.
* @return integer the number of data
model
s in the current page.
*/
public
function
getCount
();
/**
* Returns the total number of data
item
s.
* Returns the total number of data
model
s.
* When [[pagination]] is false, this is the same as [[count]].
* @return integer total number of possible data
item
s.
* @return integer total number of possible data
model
s.
*/
public
function
getTotalCount
();
/**
* Returns the data
item
s in the current page.
* @return array the list of data
item
s in the current page.
* Returns the data
model
s in the current page.
* @return array the list of data
model
s in the current page.
*/
public
function
get
Item
s
();
public
function
get
Model
s
();
/**
* Returns the key values associated with the data
item
s.
* @return array the list of key values corresponding to [[
items]]. Each data item in [[item
s]]
* Returns the key values associated with the data
model
s.
* @return array the list of key values corresponding to [[
models]]. Each data model in [[model
s]]
* is uniquely identified by the corresponding key value in this array.
*/
public
function
getKeys
();
...
...
framework/yii/data/Sort.php
View file @
f78a77df
...
...
@@ -191,17 +191,18 @@ class Sort extends Object
{
$attributes
=
array
();
foreach
(
$this
->
attributes
as
$name
=>
$attribute
)
{
if
(
is_array
(
$attribute
))
{
$attributes
[
$name
]
=
$attribute
;
if
(
!
isset
(
$attribute
[
'label'
]))
{
$attributes
[
$name
][
'label'
]
=
Inflector
::
camel2words
(
$name
);
}
}
else
{
if
(
!
is_array
(
$attribute
))
{
$attributes
[
$attribute
]
=
array
(
'asc'
=>
array
(
$attribute
=>
self
::
ASC
),
'desc'
=>
array
(
$attribute
=>
self
::
DESC
),
'label'
=>
Inflector
::
camel2words
(
$attribute
),
);
}
elseif
(
!
isset
(
$attribute
[
'asc'
],
$attribute
[
'desc'
],
$attribute
[
'label'
]))
{
$attributes
[
$name
]
=
array_merge
(
array
(
'asc'
=>
array
(
$name
=>
self
::
ASC
),
'desc'
=>
array
(
$name
=>
self
::
DESC
),
'label'
=>
Inflector
::
camel2words
(
$name
),
),
$attribute
);
}
}
$this
->
attributes
=
$attributes
;
...
...
framework/yii/db/ActiveQuery.php
View file @
f78a77df
...
...
@@ -124,10 +124,14 @@ class ActiveQuery extends Query
{
$command
=
$this
->
createCommand
(
$db
);
$row
=
$command
->
queryOne
();
if
(
$row
!==
false
&&
!
$this
->
asArray
)
{
/** @var $class ActiveRecord */
$class
=
$this
->
modelClass
;
$model
=
$class
::
create
(
$row
);
if
(
$row
!==
false
)
{
if
(
$this
->
asArray
)
{
$model
=
$row
;
}
else
{
/** @var $class ActiveRecord */
$class
=
$this
->
modelClass
;
$model
=
$class
::
create
(
$row
);
}
if
(
!
empty
(
$this
->
with
))
{
$models
=
array
(
$model
);
$this
->
populateRelations
(
$models
,
$this
->
with
);
...
...
@@ -135,7 +139,7 @@ class ActiveQuery extends Query
}
return
$model
;
}
else
{
return
$row
===
false
?
null
:
$row
;
return
null
;
}
}
...
...
framework/yii/db/ActiveRecord.php
View file @
f78a77df
...
...
@@ -535,6 +535,16 @@ class ActiveRecord extends Model
}
}
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return boolean whether the model has an attribute with the specified name.
*/
public
function
hasAttribute
(
$name
)
{
return
isset
(
$this
->
_attributes
[
$name
])
||
isset
(
$this
->
getTableSchema
()
->
columns
[
$name
]);
}
/**
* Returns the old attribute values.
* @return array the old attribute values (name-value pairs)
...
...
@@ -1400,10 +1410,10 @@ class ActiveRecord extends Model
* @param string $class the class name to be namespaced
* @return string the namespaced class name
*/
protected
function
getNamespacedClass
(
$class
)
protected
static
function
getNamespacedClass
(
$class
)
{
if
(
strpos
(
$class
,
'\\'
)
===
false
)
{
$reflector
=
new
\ReflectionClass
(
$this
);
$reflector
=
new
\ReflectionClass
(
static
::
className
()
);
return
$reflector
->
getNamespaceName
()
.
'\\'
.
$class
;
}
else
{
return
$class
;
...
...
framework/yii/db/Command.php
View file @
f78a77df
...
...
@@ -146,9 +146,9 @@ class Command extends \yii\base\Component
try
{
$this
->
pdoStatement
=
$this
->
db
->
pdo
->
prepare
(
$sql
);
}
catch
(
\Exception
$e
)
{
Yii
::
error
(
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
,
__METHOD__
)
;
$message
=
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$
e
->
getMessage
()
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
throw
new
Exception
(
$
message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
}
}
...
...
@@ -293,10 +293,7 @@ class Command extends \yii\base\Component
return
$n
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
$message
=
$e
->
getMessage
();
Yii
::
error
(
"
$message
\n
Failed to execute SQL:
$rawSql
"
,
__METHOD__
);
$message
=
$e
->
getMessage
()
.
"
\n
The SQL being executed was:
$rawSql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
...
...
@@ -430,8 +427,7 @@ class Command extends \yii\base\Component
return
$result
;
}
catch
(
\Exception
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
$message
=
$e
->
getMessage
();
Yii
::
error
(
"
$message
\n
Command::
$method
() failed:
$rawSql
"
,
__METHOD__
);
$message
=
$e
->
getMessage
()
.
"
\n
The SQL being executed was:
$rawSql
"
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
...
...
framework/yii/db/Connection.php
View file @
f78a77df
...
...
@@ -307,9 +307,7 @@ class Connection extends Component
Yii
::
endProfile
(
$token
,
__METHOD__
);
}
catch
(
\PDOException
$e
)
{
Yii
::
endProfile
(
$token
,
__METHOD__
);
Yii
::
error
(
"Failed to open DB connection (
{
$this
->
dsn
}
): "
.
$e
->
getMessage
(),
__METHOD__
);
$message
=
YII_DEBUG
?
'Failed to open DB connection: '
.
$e
->
getMessage
()
:
'Failed to open DB connection.'
;
throw
new
Exception
(
$message
,
$e
->
errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
throw
new
Exception
(
$e
->
getMessage
(),
$e
->
errorInfo
,
(
int
)
$e
->
getCode
(),
$e
);
}
}
}
...
...
framework/yii/debug/panels/LogPanel.php
View file @
f78a77df
...
...
@@ -55,7 +55,7 @@ EOD;
foreach
(
$this
->
data
[
'messages'
]
as
$log
)
{
list
(
$message
,
$level
,
$category
,
$time
,
$traces
)
=
$log
;
$time
=
date
(
'H:i:s.'
,
$time
)
.
sprintf
(
'%03d'
,
(
int
)((
$time
-
(
int
)
$time
)
*
1000
));
$message
=
Html
::
encode
(
$message
);
$message
=
nl2br
(
Html
::
encode
(
$message
)
);
if
(
!
empty
(
$traces
))
{
$message
.=
Html
::
ul
(
$traces
,
array
(
'class'
=>
'trace'
,
...
...
framework/yii/debug/panels/ProfilingPanel.php
View file @
f78a77df
...
...
@@ -33,10 +33,10 @@ class ProfilingPanel extends Panel
return
<<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="
t
otal processing time">Time: <span class="label">$time</span></a>
<a href="$url" title="
T
otal processing time">Time: <span class="label">$time</span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="$url" title="
p
eak memory consumption">Memory: <span class="label">$memory</span></a>
<a href="$url" title="
P
eak memory consumption">Memory: <span class="label">$memory</span></a>
</div>
EOD;
}
...
...
framework/yii/debug/panels/RequestPanel.php
View file @
f78a77df
...
...
@@ -12,6 +12,7 @@ use yii\base\InlineAction;
use
yii\bootstrap\Tabs
;
use
yii\debug\Panel
;
use
yii\helpers\Html
;
use
yii\web\Response
;
/**
* Debugger panel that collects and displays request data.
...
...
@@ -29,8 +30,23 @@ class RequestPanel extends Panel
public
function
getSummary
()
{
$url
=
$this
->
getUrl
();
$statusCode
=
$this
->
data
[
'statusCode'
];
if
(
$statusCode
===
null
)
{
$statusCode
=
200
;
}
if
(
$statusCode
>=
200
&&
$statusCode
<
300
)
{
$class
=
'label-success'
;
}
elseif
(
$statusCode
>=
100
&&
$statusCode
<
200
)
{
$class
=
'label-info'
;
}
else
{
$class
=
'label-important'
;
}
$statusText
=
Html
::
encode
(
isset
(
Response
::
$httpStatuses
[
$statusCode
])
?
Response
::
$httpStatuses
[
$statusCode
]
:
''
);
return
<<<EOD
<div class="yii-debug-toolbar-block">
<a href="$url" title="Status code: $statusCode $statusText"><span class="label $class">$statusCode</span></a>
</div>
<div class="yii-debug-toolbar-block">
<a href="$url">Action: <span class="label">{$this->data['action']}</span></a>
</div>
...
...
@@ -113,6 +129,7 @@ EOD;
$session
=
Yii
::
$app
->
getComponent
(
'session'
,
false
);
return
array
(
'flashes'
=>
$session
?
$session
->
getAllFlashes
()
:
array
(),
'statusCode'
=>
Yii
::
$app
->
getResponse
()
->
getStatusCode
(),
'requestHeaders'
=>
$requestHeaders
,
'responseHeaders'
=>
$responseHeaders
,
'route'
=>
Yii
::
$app
->
requestedAction
?
Yii
::
$app
->
requestedAction
->
getUniqueId
()
:
Yii
::
$app
->
requestedRoute
,
...
...
framework/yii/helpers/HtmlBase.php
View file @
f78a77df
...
...
@@ -1339,11 +1339,12 @@ class HtmlBase
*
* - is an empty string: the currently requested URL will be returned;
* - is a non-empty string: it will first be processed by [[Yii::getAlias()]]. If the result
* is an absolute URL, it will be returned with any change further; Otherwise, the result
* is an absolute URL, it will be returned with
out
any change further; Otherwise, the result
* will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
* - is an array: the first array element is considered a route, while the rest of the name-value
* pairs are treated as the parameters to be used for URL creation using [[\yii\web\Controller::createUrl()]].
* For example: `array('post/index', 'page' => 2)`, `array('index')`.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
* @param array|string $url the parameter to be used to generate a valid URL
* @return string the normalized URL
...
...
@@ -1355,7 +1356,7 @@ class HtmlBase
if
(
isset
(
$url
[
0
]))
{
$route
=
$url
[
0
];
$params
=
array_splice
(
$url
,
1
);
if
(
Yii
::
$app
->
controller
!==
null
)
{
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\Controller
)
{
return
Yii
::
$app
->
controller
->
createUrl
(
$route
,
$params
);
}
else
{
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
...
...
framework/yii/helpers/SecurityBase.php
View file @
f78a77df
...
...
@@ -120,7 +120,10 @@ class SecurityBase
static
$keys
;
$keyFile
=
Yii
::
$app
->
getRuntimePath
()
.
'/keys.php'
;
if
(
$keys
===
null
)
{
$keys
=
is_file
(
$keyFile
)
?
require
(
$keyFile
)
:
array
();
$keys
=
array
();
if
(
is_file
(
$keyFile
))
{
$keys
=
require
(
$keyFile
);
}
}
if
(
!
isset
(
$keys
[
$name
]))
{
$keys
[
$name
]
=
static
::
generateRandomKey
(
$length
);
...
...
framework/yii/requirements/requirements.php
View file @
f78a77df
...
...
@@ -41,7 +41,7 @@ return array(
array
(
'name'
=>
'Intl extension'
,
'mandatory'
=>
false
,
'condition'
=>
$this
->
checkPhpExtensionVersion
(
'intl'
,
'1.0.2'
),
'condition'
=>
$this
->
checkPhpExtensionVersion
(
'intl'
,
'1.0.2'
,
'>='
),
'by'
=>
'<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support'
,
'memo'
=>
'PHP Intl extension 1.0.2 or higher is required when you want to use <abbr title="Internationalized domain names">IDN</abbr>-feature of EmailValidator or UrlValidator or the <code>yii\i18n\Formatter</code> class.'
),
...
...
framework/yii/validators/Validator.php
View file @
f78a77df
...
...
@@ -49,7 +49,7 @@ abstract class Validator extends Component
*/
public
static
$builtInValidators
=
array
(
'boolean'
=>
'yii\validators\BooleanValidator'
,
'captcha'
=>
'yii\
validators
\CaptchaValidator'
,
'captcha'
=>
'yii\
captcha
\CaptchaValidator'
,
'compare'
=>
'yii\validators\CompareValidator'
,
'date'
=>
'yii\validators\DateValidator'
,
'default'
=>
'yii\validators\DefaultValueValidator'
,
...
...
framework/yii/views/errorHandler/callStackItem.php
View file @
f78a77df
...
...
@@ -8,19 +8,19 @@
* @var string[] $lines
* @var integer $begin
* @var integer $end
* @var \yii\base\ErrorHandler $
this
* @var \yii\base\ErrorHandler $
handler
*/
?>
<li
class=
"
<?php
if
(
!
$
this
->
isCoreFile
(
$file
)
||
$index
===
1
)
echo
'application'
;
?>
call-stack-item"
<li
class=
"
<?php
if
(
!
$
handler
->
isCoreFile
(
$file
)
||
$index
===
1
)
echo
'application'
;
?>
call-stack-item"
data-line=
"
<?php
echo
(
int
)(
$line
-
$begin
);
?>
"
>
<div
class=
"element-wrap"
>
<div
class=
"element"
>
<span
class=
"item-number"
>
<?php
echo
(
int
)
$index
;
?>
.
</span>
<span
class=
"text"
>
<?php
if
(
$file
!==
null
)
echo
'in '
.
$
this
->
htmlEncode
(
$file
);
?>
</span>
<span
class=
"text"
>
<?php
if
(
$file
!==
null
)
echo
'in '
.
$
handler
->
htmlEncode
(
$file
);
?>
</span>
<?php
if
(
$method
!==
null
)
:
?>
<span
class=
"call"
>
<?php
if
(
$file
!==
null
)
echo
'–'
?>
<?php
if
(
$class
!==
null
)
echo
$
this
->
addTypeLinks
(
$class
)
.
'::'
;
?><?php
echo
$this
->
addTypeLinks
(
$method
.
'()'
);
?>
<?php
if
(
$class
!==
null
)
echo
$
handler
->
addTypeLinks
(
$class
)
.
'::'
;
?><?php
echo
$handler
->
addTypeLinks
(
$method
.
'()'
);
?>
</span>
<?php
endif
;
?>
<span
class=
"at"
>
<?php
if
(
$line
!==
null
)
echo
'at line'
;
?>
</span>
...
...
@@ -36,7 +36,7 @@
<pre>
<?php
// fill empty lines with a whitespace to avoid rendering problems in opera
for
(
$i
=
$begin
;
$i
<=
$end
;
++
$i
)
{
echo
(
trim
(
$lines
[
$i
])
==
''
)
?
"
\n
"
:
$
this
->
htmlEncode
(
$lines
[
$i
]);
echo
(
trim
(
$lines
[
$i
])
==
''
)
?
"
\n
"
:
$
handler
->
htmlEncode
(
$lines
[
$i
]);
}
?>
</pre>
</div>
...
...
framework/yii/views/errorHandler/error.php
View file @
f78a77df
<?php
/**
* @var \Exception $exception
* @var \yii\base\ErrorHandler $
this
* @var \yii\base\ErrorHandler $
handler
*/
$title
=
$
this
->
htmlEncode
(
$exception
instanceof
\yii\base\Exception
?
$exception
->
getName
()
:
get_class
(
$exception
));
$title
=
$
handler
->
htmlEncode
(
$exception
instanceof
\yii\base\Exception
?
$exception
->
getName
()
:
get_class
(
$exception
));
?>
<?php
if
(
method_exists
(
$this
,
'beginPage'
))
$this
->
beginPage
();
?>
<!DOCTYPE html>
<html>
<head>
...
...
@@ -50,16 +51,18 @@ $title = $this->htmlEncode($exception instanceof \yii\base\Exception ? $exceptio
</head>
<body>
<h1>
<?php
echo
$title
?>
</h1>
<h2>
<?php
echo
nl2br
(
$this
->
htmlEncode
(
$exception
->
getMessage
()))
?>
</h2>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
<div
class=
"version"
>
<?php
echo
date
(
'Y-m-d H:i:s'
,
time
())
?>
</div>
<h1>
<?php
echo
$title
?>
</h1>
<h2>
<?php
echo
nl2br
(
$handler
->
htmlEncode
(
$exception
->
getMessage
()))
?>
</h2>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
<div
class=
"version"
>
<?php
echo
date
(
'Y-m-d H:i:s'
,
time
())
?>
</div>
<?php
if
(
method_exists
(
$this
,
'endBody'
))
$this
->
endBody
();
// to allow injecting code into body (mostly by Yii Debug Toolbar) ?>
</
body
>
</
html
>
<?
php
if
(
method_exists
(
$this
,
'endPage'
))
$this
->
endPage
();
?>
framework/yii/views/errorHandler/exception.php
View file @
f78a77df
This diff is collapsed.
Click to expand it.
framework/yii/views/errorHandler/previousException.php
View file @
f78a77df
<?php
/**
* @var \yii\base\Exception $exception
* @var \yii\base\ErrorHandler $
this
* @var \yii\base\ErrorHandler $
handler
*/
?>
<div
class=
"previous"
>
...
...
@@ -9,13 +9,13 @@
<h2>
<span>
Caused by:
</span>
<?php
if
(
$exception
instanceof
\yii\base\Exception
)
:
?>
<span>
<?php
echo
$
this
->
htmlEncode
(
$exception
->
getName
());
?>
</span>
–
<?php
echo
$
this
->
addTypeLinks
(
get_class
(
$exception
));
?>
<span>
<?php
echo
$
handler
->
htmlEncode
(
$exception
->
getName
());
?>
</span>
–
<?php
echo
$
handler
->
addTypeLinks
(
get_class
(
$exception
));
?>
<?php
else
:
?>
<span>
<?php
echo
$
this
->
htmlEncode
(
get_class
(
$exception
));
?>
</span>
<span>
<?php
echo
$
handler
->
htmlEncode
(
get_class
(
$exception
));
?>
</span>
<?php
endif
;
?>
</h2>
<h3>
<?php
echo
$
this
->
htmlEncode
(
$exception
->
getMessage
());
?>
</h3>
<h3>
<?php
echo
$
handler
->
htmlEncode
(
$exception
->
getMessage
());
?>
</h3>
<p>
in
<span
class=
"file"
>
<?php
echo
$exception
->
getFile
();
?>
</span>
at line
<span
class=
"line"
>
<?php
echo
$exception
->
getLine
();
?>
</span></p>
<?php
echo
$
this
->
renderPreviousExceptions
(
$exception
);
?>
<?php
echo
$
handler
->
renderPreviousExceptions
(
$exception
);
?>
</div>
framework/yii/web/Request.php
View file @
f78a77df
...
...
@@ -864,7 +864,7 @@ class Request extends \yii\base\Request
private
$_cookieValidationKey
;
/**
* @return string the secret key used for cookie validation. If it was set previously,
* @return string the secret key used for cookie validation. If it was
not
set previously,
* a random key will be generated and used.
*/
public
function
getCookieValidationKey
()
...
...
framework/yii/web/Response.php
View file @
f78a77df
...
...
@@ -258,7 +258,6 @@ class Response extends \yii\base\Response
$this
->
sendHeaders
();
$this
->
sendContent
();
$this
->
trigger
(
self
::
EVENT_AFTER_SEND
,
new
ResponseEvent
(
$this
));
$this
->
clear
();
}
/**
...
...
framework/yii/widgets/DetailView.php
View file @
f78a77df
...
...
@@ -21,7 +21,7 @@ use yii\helpers\Inflector;
* DetailView displays the detail of a single data [[model]].
*
* DetailView is best used for displaying a model in a regular format (e.g. each model attribute
* is displayed as a row in a table.) The model can be either an instance of [[Model]]
or
* is displayed as a row in a table.) The model can be either an instance of [[Model]]
* or an associative array.
*
* DetailView uses the [[attributes]] property to determines which model attributes
...
...
@@ -105,7 +105,7 @@ class DetailView extends Widget
public
function
init
()
{
if
(
$this
->
model
===
null
)
{
throw
new
InvalidConfigException
(
'Please specify the "
data
" property.'
);
throw
new
InvalidConfigException
(
'Please specify the "
model
" property.'
);
}
if
(
$this
->
formatter
==
null
)
{
$this
->
formatter
=
Yii
::
$app
->
getFormatter
();
...
...
@@ -166,7 +166,7 @@ class DetailView extends Widget
}
elseif
(
is_array
(
$this
->
model
))
{
$this
->
attributes
=
array_keys
(
$this
->
model
);
}
else
{
throw
new
InvalidConfigException
(
'The "
data
" property must be either an array or an object.'
);
throw
new
InvalidConfigException
(
'The "
model
" property must be either an array or an object.'
);
}
sort
(
$this
->
attributes
);
}
...
...
framework/yii/widgets/GridView.php
0 → 100644
View file @
f78a77df
This diff is collapsed.
Click to expand it.
framework/yii/widgets/ListView.php
View file @
f78a77df
...
...
@@ -19,7 +19,7 @@ use yii\helpers\Html;
class
ListView
extends
ListViewBase
{
/**
* @var array the HTML attributes for the container of the rendering result of each data
item
.
* @var array the HTML attributes for the container of the rendering result of each data
model
.
* The "tag" element specifies the tag name of the container element and defaults to "div".
* If "tag" is false, it means no container element will be rendered.
*/
...
...
@@ -29,7 +29,7 @@ class ListView extends ListViewBase
* for rendering each data item. If it specifies a view name, the following variables will
* be available in the view:
*
* - `$
item`: mixed, the data item
* - `$
model`: mixed, the data model
* - `$key`: mixed, the key value associated with the data item
* - `$index`: integer, the zero-based index of the data item in the items array returned by [[dataProvider]].
* - `$widget`: ListView, this widget instance
...
...
@@ -39,7 +39,7 @@ class ListView extends ListViewBase
* If this property is specified as a callback, it should have the following signature:
*
* ~~~
* function ($
item
, $key, $index, $widget)
* function ($
model
, $key, $index, $widget)
* ~~~
*/
public
$itemView
;
...
...
@@ -50,40 +50,40 @@ class ListView extends ListViewBase
/**
* Renders all data
item
s.
* Renders all data
model
s.
* @return string the rendering result
*/
public
function
renderItems
()
{
$
items
=
$this
->
dataProvider
->
getItem
s
();
$
models
=
$this
->
dataProvider
->
getModel
s
();
$keys
=
$this
->
dataProvider
->
getKeys
();
$rows
=
array
();
foreach
(
array_values
(
$
items
)
as
$index
=>
$item
)
{
$rows
[]
=
$this
->
renderItem
(
$
item
,
$keys
[
$index
],
$index
);
foreach
(
array_values
(
$
models
)
as
$index
=>
$model
)
{
$rows
[]
=
$this
->
renderItem
(
$
model
,
$keys
[
$index
],
$index
);
}
return
implode
(
$this
->
separator
,
$rows
);
}
/**
* Renders a single data
item
.
* @param mixed $
item the data item
to be rendered
* @param mixed $key the key value associated with the data
item
* @param integer $index the zero-based index of the data
item in the item
array returned by [[dataProvider]].
* Renders a single data
model
.
* @param mixed $
model the data model
to be rendered
* @param mixed $key the key value associated with the data
model
* @param integer $index the zero-based index of the data
model in the model
array returned by [[dataProvider]].
* @return string the rendering result
*/
public
function
renderItem
(
$
item
,
$key
,
$index
)
public
function
renderItem
(
$
model
,
$key
,
$index
)
{
if
(
$this
->
itemView
===
null
)
{
$content
=
$key
;
}
elseif
(
is_string
(
$this
->
itemView
))
{
$content
=
$this
->
getView
()
->
render
(
$this
->
itemView
,
array
(
'
item'
=>
$item
,
'
model'
=>
$model
,
'key'
=>
$key
,
'index'
=>
$index
,
'widget'
=>
$this
,
));
}
else
{
$content
=
call_user_func
(
$this
->
itemView
,
$
item
,
$key
,
$index
,
$this
);
$content
=
call_user_func
(
$this
->
itemView
,
$
model
,
$key
,
$index
,
$this
);
}
$options
=
$this
->
itemOptions
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'div'
);
...
...
framework/yii/widgets/ListViewBase.php
View file @
f78a77df
...
...
@@ -70,7 +70,7 @@ abstract class ListViewBase extends Widget
/**
* Renders the data
item
s.
* Renders the data
model
s.
* @return string the rendering result.
*/
abstract
public
function
renderItems
();
...
...
@@ -91,8 +91,9 @@ abstract class ListViewBase extends Widget
public
function
run
()
{
if
(
$this
->
dataProvider
->
getCount
()
>
0
||
$this
->
empty
===
false
)
{
$content
=
preg_replace_callback
(
"/
{
\\w+
}
/"
,
function
(
$matches
)
{
$content
=
$this
->
renderSection
(
$matches
[
0
]);
$widget
=
$this
;
$content
=
preg_replace_callback
(
"/
{
\\w+
}
/"
,
function
(
$matches
)
use
(
$widget
)
{
$content
=
$widget
->
renderSection
(
$matches
[
0
]);
return
$content
===
false
?
$matches
[
0
]
:
$content
;
},
$this
->
layout
);
}
else
{
...
...
@@ -108,7 +109,7 @@ abstract class ListViewBase extends Widget
* @param string $name the section name, e.g., `{summary}`, `{items}`.
* @return string|boolean the rendering result of the section, or false if the named section is not supported.
*/
p
rotected
function
renderSection
(
$name
)
p
ublic
function
renderSection
(
$name
)
{
switch
(
$name
)
{
case
'{summary}'
:
...
...
framework/yii/widgets/grid/CheckboxColumn.php
0 → 100644
View file @
f78a77df
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets\grid
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
CheckboxColumn
extends
Column
{
public
$checked
;
/**
* @var string a PHP expression that will be evaluated for every data cell and whose result will
* determine if checkbox for each data cell is disabled. In this expression, you can use the following variables:
* <ul>
* <li><code>$row</code> the row number (zero-based)</li>
* <li><code>$data</code> the data model for the row</li>
* <li><code>$this</code> the column object</li>
* </ul>
* The PHP expression will be evaluated using {@link evaluateExpression}.
*
* A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
* please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}.
*
* Note that expression result will overwrite value set with <code>checkBoxHtmlOptions['disabled']</code>.
* @since 1.1.13
*/
public
$disabled
;
/**
* @var array the HTML options for the data cell tags.
*/
public
$htmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the header cell tag.
*/
public
$headerHtmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the footer cell tag.
*/
public
$footerHtmlOptions
=
array
(
'class'
=>
'checkbox-column'
);
/**
* @var array the HTML options for the checkboxes.
*/
public
$checkBoxHtmlOptions
=
array
();
/**
* @var integer the number of rows that can be checked.
* Possible values:
* <ul>
* <li>0 - the state of the checkbox cannot be changed (read-only mode)</li>
* <li>1 - only one row can be checked. Checking a checkbox has nothing to do with selecting the row</li>
* <li>2 or more - multiple checkboxes can be checked. Checking a checkbox has nothing to do with selecting the row</li>
* <li>null - {@link CGridView::selectableRows} is used to control how many checkboxes can be checked.
* Checking a checkbox will also select the row.</li>
* </ul>
* You may also call the JavaScript function <code>$(gridID).yiiGridView('getChecked', columnID)</code>
* to retrieve the key values of the checked rows.
* @since 1.1.6
*/
public
$selectableRows
=
null
;
/**
* @var string the template to be used to control the layout of the header cell.
* The token "{item}" is recognized and it will be replaced with a "check all" checkbox.
* By default if in multiple checking mode, the header cell will display an additional checkbox,
* clicking on which will check or uncheck all of the checkboxes in the data cells.
* See {@link selectableRows} for more details.
* @since 1.1.11
*/
public
$headerTemplate
=
'{item}'
;
/**
* Initializes the column.
* This method registers necessary client script for the checkbox column.
*/
public
function
init
()
{
if
(
isset
(
$this
->
checkBoxHtmlOptions
[
'name'
]))
{
$name
=
$this
->
checkBoxHtmlOptions
[
'name'
];
}
else
{
$name
=
$this
->
id
;
if
(
substr
(
$name
,
-
2
)
!==
'[]'
)
{
$name
.=
'[]'
;
}
$this
->
checkBoxHtmlOptions
[
'name'
]
=
$name
;
}
$name
=
strtr
(
$name
,
array
(
'['
=>
"
\\
["
,
']'
=>
"
\\
]"
));
if
(
$this
->
selectableRows
===
null
)
{
if
(
isset
(
$this
->
checkBoxHtmlOptions
[
'class'
]))
{
$this
->
checkBoxHtmlOptions
[
'class'
]
.=
' select-on-check'
;
}
else
{
$this
->
checkBoxHtmlOptions
[
'class'
]
=
'select-on-check'
;
}
return
;
}
$cball
=
$cbcode
=
''
;
if
(
$this
->
selectableRows
==
0
)
{
//.. read only
$cbcode
=
"return false;"
;
}
elseif
(
$this
->
selectableRows
==
1
)
{
//.. only one can be checked, uncheck all other
$cbcode
=
"jQuery(
\"
input:not(#
\"
+this.id+
\"
)[name='
$name
']
\"
).prop('checked',false);"
;
}
elseif
(
strpos
(
$this
->
headerTemplate
,
'{item}'
)
!==
false
)
{
//.. process check/uncheck all
$cball
=
<<<CBALL
jQuery(document).on('click','#{$this->id}_all',function() {
var checked=this.checked;
jQuery("input[name='$name']:enabled").each(function() {this.checked=checked;});
});
CBALL;
$cbcode
=
"jQuery('#
{
$this
->
id
}
_all').prop('checked', jQuery(
\"
input[name='
$name
']
\"
).length==jQuery(
\"
input[name='
$name
']:checked
\"
).length);"
;
}
if
(
$cbcode
!==
''
)
{
$js
=
$cball
;
$js
.=
<<<EOD
jQuery(document).on('click', "input[name='$name']", function() {
$cbcode
});
EOD;
Yii
::
app
()
->
getClientScript
()
->
registerScript
(
__CLASS__
.
'#'
.
$this
->
id
,
$js
);
}
}
/**
* Renders the header cell content.
* This method will render a checkbox in the header when {@link selectableRows} is greater than 1
* or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1.
*/
protected
function
renderHeaderCellContent
()
{
if
(
trim
(
$this
->
headerTemplate
)
===
''
)
{
echo
$this
->
grid
->
blankDisplay
;
return
;
}
$item
=
''
;
if
(
$this
->
selectableRows
===
null
&&
$this
->
grid
->
selectableRows
>
1
)
{
$item
=
CHtml
::
checkBox
(
$this
->
id
.
'_all'
,
false
,
array
(
'class'
=>
'select-on-check-all'
));
}
elseif
(
$this
->
selectableRows
>
1
)
{
$item
=
CHtml
::
checkBox
(
$this
->
id
.
'_all'
,
false
);
}
else
{
ob_start
();
parent
::
renderHeaderCellContent
();
$item
=
ob_get_clean
();
}
echo
strtr
(
$this
->
headerTemplate
,
array
(
'{item}'
=>
$item
,
));
}
/**
* Renders the data cell content.
* This method renders a checkbox in the data cell.
* @param integer $row the row number (zero-based)
* @param mixed $data the data associated with the row
*/
protected
function
renderDataCellContent
(
$row
,
$data
)
{
if
(
$this
->
value
!==
null
)
{
$value
=
$this
->
evaluateExpression
(
$this
->
value
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
}
elseif
(
$this
->
name
!==
null
)
{
$value
=
CHtml
::
value
(
$data
,
$this
->
name
);
}
else
{
$value
=
$this
->
grid
->
dataProvider
->
keys
[
$row
];
}
$checked
=
false
;
if
(
$this
->
checked
!==
null
)
{
$checked
=
$this
->
evaluateExpression
(
$this
->
checked
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
}
$options
=
$this
->
checkBoxHtmlOptions
;
if
(
$this
->
disabled
!==
null
)
{
$options
[
'disabled'
]
=
$this
->
evaluateExpression
(
$this
->
disabled
,
array
(
'data'
=>
$data
,
'row'
=>
$row
));
}
$name
=
$options
[
'name'
];
unset
(
$options
[
'name'
]);
$options
[
'value'
]
=
$value
;
$options
[
'id'
]
=
$this
->
id
.
'_'
.
$row
;
echo
CHtml
::
checkBox
(
$name
,
$checked
,
$options
);
}
}
framework/yii/widgets/grid/Column.php
0 → 100644
View file @
f78a77df
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets\grid
;
use
Closure
;
use
yii\base\Object
;
use
yii\helpers\Html
;
use
yii\widgets\GridView
;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Column
extends
Object
{
/**
* @var string the ID of this column. This value should be unique among all grid view columns.
* If this is not set, it will be assigned one automatically.
*/
public
$id
;
/**
* @var GridView the grid view object that owns this column.
*/
public
$grid
;
/**
* @var string the header cell content. Note that it will not be HTML-encoded.
*/
public
$header
;
/**
* @var string the footer cell content. Note that it will not be HTML-encoded.
*/
public
$footer
;
/**
* @var callable
*/
public
$content
;
/**
* @var boolean whether this column is visible. Defaults to true.
*/
public
$visible
=
true
;
public
$options
=
array
();
public
$headerOptions
=
array
();
/**
* @var array|\Closure
*/
public
$bodyOptions
=
array
();
public
$footerOptions
=
array
();
/**
* @var array the HTML attributes for the filter cell tag.
*/
public
$filterOptions
=
array
();
/**
* Renders the header cell.
*/
public
function
renderHeaderCell
()
{
return
Html
::
tag
(
'th'
,
$this
->
renderHeaderCellContent
(),
$this
->
headerOptions
);
}
/**
* Renders the footer cell.
*/
public
function
renderFooterCell
()
{
return
Html
::
tag
(
'td'
,
$this
->
renderFooterCellContent
(),
$this
->
footerOptions
);
}
/**
* Renders a data cell.
* @param mixed $model the data model being rendered
* @param integer $index the zero-based index of the data item among the item array returned by [[dataProvider]].
* @return string the rendering result
*/
public
function
renderDataCell
(
$model
,
$index
)
{
if
(
$this
->
bodyOptions
instanceof
Closure
)
{
$options
=
call_user_func
(
$this
->
bodyOptions
,
$model
,
$index
,
$this
);
}
else
{
$options
=
$this
->
bodyOptions
;
}
return
Html
::
tag
(
'td'
,
$this
->
renderDataCellContent
(
$model
,
$index
),
$options
);
}
/**
* Renders the filter cell.
*/
public
function
renderFilterCell
()
{
return
Html
::
tag
(
'td'
,
$this
->
renderFilterCellContent
(),
$this
->
filterOptions
);
}
/**
* Renders the header cell content.
* The default implementation simply renders {@link header}.
* This method may be overridden to customize the rendering of the header cell.
* @return string the rendering result
*/
protected
function
renderHeaderCellContent
()
{
return
trim
(
$this
->
header
)
!==
''
?
$this
->
header
:
$this
->
grid
->
emptyCell
;
}
/**
* Renders the footer cell content.
* The default implementation simply renders {@link footer}.
* This method may be overridden to customize the rendering of the footer cell.
* @return string the rendering result
*/
protected
function
renderFooterCellContent
()
{
return
trim
(
$this
->
footer
)
!==
''
?
$this
->
footer
:
$this
->
grid
->
emptyCell
;
}
/**
* Renders the data cell content.
* @param mixed $model the data model
* @param integer $index the zero-based index of the data model among the models array returned by [[dataProvider]].
* @return string the rendering result
*/
protected
function
renderDataCellContent
(
$model
,
$index
)
{
if
(
$this
->
content
!==
null
)
{
return
call_user_func
(
$this
->
content
,
$model
,
$index
,
$this
);
}
else
{
return
$this
->
grid
->
emptyCell
;
}
}
/**
* Renders the filter cell content.
* The default implementation simply renders a space.
* This method may be overridden to customize the rendering of the filter cell (if any).
* @return string the rendering result
*/
protected
function
renderFilterCellContent
()
{
return
$this
->
grid
->
emptyCell
;
}
}
framework/yii/widgets/grid/DataColumn.php
0 → 100644
View file @
f78a77df
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets\grid
;
use
yii\base\InvalidConfigException
;
use
yii\base\Model
;
use
yii\data\ActiveDataProvider
;
use
yii\db\ActiveQuery
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\helpers\Inflector
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
DataColumn
extends
Column
{
public
$attribute
;
public
$value
;
public
$format
;
/**
* @var boolean whether to allow sorting by this column. If true and [[attribute]] is found in
* the sort definition of [[GridView::dataProvider]], then the header cell of this column
* will contain a link that may trigger the sorting when being clicked.
*/
public
$enableSorting
=
true
;
/**
* @var string|array|boolean the HTML code representing a filter input (eg a text field, a dropdown list)
* that is used for this data column. This property is effective only when
* {@link CGridView::filter} is set.
* If this property is not set, a text field will be generated as the filter input;
* If this property is an array, a dropdown list will be generated that uses this property value as
* the list options.
* If you don't want a filter for this data column, set this value to false.
*/
public
$filter
;
protected
function
renderHeaderCellContent
()
{
if
(
$this
->
attribute
!==
null
&&
$this
->
header
===
null
)
{
$provider
=
$this
->
grid
->
dataProvider
;
if
(
$this
->
enableSorting
&&
(
$sort
=
$provider
->
getSort
())
!==
false
&&
$sort
->
hasAttribute
(
$this
->
attribute
))
{
return
$sort
->
link
(
$this
->
attribute
);
}
$models
=
$provider
->
getModels
();
if
((
$model
=
reset
(
$models
))
instanceof
Model
)
{
/** @var Model $model */
return
$model
->
getAttributeLabel
(
$this
->
attribute
);
}
elseif
(
$provider
instanceof
ActiveDataProvider
)
{
if
(
$provider
->
query
instanceof
ActiveQuery
)
{
/** @var Model $model */
$model
=
new
$provider
->
query
->
modelClass
;
return
$model
->
getAttributeLabel
(
$this
->
attribute
);
}
}
return
Inflector
::
camel2words
(
$this
->
attribute
);
}
else
{
return
parent
::
renderHeaderCellContent
();
}
}
protected
function
renderFilterCellContent
()
{
if
(
is_string
(
$this
->
filter
))
{
return
$this
->
filter
;
}
elseif
(
$this
->
filter
!==
false
&&
$this
->
grid
->
filterModel
instanceof
Model
&&
$this
->
attribute
!==
null
)
{
if
(
is_array
(
$this
->
filter
))
{
return
Html
::
activeDropDownList
(
$this
->
grid
->
filterModel
,
$this
->
attribute
,
$this
->
filter
,
array
(
'prompt'
=>
''
));
}
else
{
return
Html
::
activeTextInput
(
$this
->
grid
->
filterModel
,
$this
->
attribute
);
}
}
else
{
return
parent
::
renderFilterCellContent
();
}
}
protected
function
renderDataCellContent
(
$model
,
$index
)
{
if
(
$this
->
value
!==
null
)
{
$value
=
call_user_func
(
$this
->
value
,
$model
,
$index
,
$this
);
}
elseif
(
$this
->
content
===
null
&&
$this
->
attribute
!==
null
)
{
$value
=
ArrayHelper
::
getValue
(
$model
,
$this
->
attribute
);
}
else
{
return
parent
::
renderDataCellContent
(
$model
,
$index
);
}
return
$this
->
grid
->
formatter
->
format
(
$value
,
$this
->
format
);
}
}
framework/yii/widgets/grid/SerialColumn.php
0 → 100644
View file @
f78a77df
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\widgets\grid
;
/**
* SerialColumn displays a column of row numbers (1-based).
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
SerialColumn
extends
Column
{
/**
* Renders the data cell content.
* @param mixed $model the data model
* @param integer $index the zero-based index of the data model among the models array returned by [[dataProvider]].
* @return string the rendering result
*/
protected
function
renderDataCellContent
(
$model
,
$index
)
{
$pagination
=
$this
->
grid
->
dataProvider
->
getPagination
();
if
(
$pagination
!==
false
)
{
return
$pagination
->
getOffset
()
+
$index
+
1
;
}
else
{
return
$index
+
1
;
}
}
}
tests/unit/data/base/Singer.php
View file @
f78a77df
...
...
@@ -15,7 +15,7 @@ class Singer extends Model
return
array
(
array
(
'lastName'
,
'default'
,
'value'
=>
'Lennon'
),
array
(
'lastName'
,
'required'
),
array
(
'underscore_style'
,
'yii\
validators
\CaptchaValidator'
),
array
(
'underscore_style'
,
'yii\
captcha
\CaptchaValidator'
),
);
}
}
tests/unit/framework/base/FormatterTest.php
View file @
f78a77df
...
...
@@ -189,4 +189,14 @@ class FormatterTest extends TestCase
$this
->
assertSame
(
"123123,12"
,
$this
->
formatter
->
asNumber
(
$value
,
2
));
$this
->
assertSame
(
$this
->
formatter
->
nullDisplay
,
$this
->
formatter
->
asNumber
(
null
));
}
public
function
testFormat
()
{
$value
=
time
();
$this
->
assertSame
(
date
(
'Y/m/d'
,
$value
),
$this
->
formatter
->
format
(
$value
,
'date'
));
$this
->
assertSame
(
date
(
'Y/m/d'
,
$value
),
$this
->
formatter
->
format
(
$value
,
'DATE'
));
$this
->
assertSame
(
date
(
'Y-m-d'
,
$value
),
$this
->
formatter
->
format
(
$value
,
array
(
'date'
,
'Y-m-d'
)));
$this
->
setExpectedException
(
'\yii\base\InvalidParamException'
);
$this
->
assertSame
(
date
(
'Y-m-d'
,
$value
),
$this
->
formatter
->
format
(
$value
,
'data'
));
}
}
tests/unit/framework/data/ActiveDataProviderTest.php
View file @
f78a77df
...
...
@@ -30,7 +30,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
$provider
=
new
ActiveDataProvider
(
array
(
'query'
=>
Order
::
find
()
->
orderBy
(
'id'
),
));
$orders
=
$provider
->
get
Item
s
();
$orders
=
$provider
->
get
Model
s
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
$orders
[
0
]
instanceof
Order
);
$this
->
assertEquals
(
array
(
1
,
2
,
3
),
$provider
->
getKeys
());
...
...
@@ -41,7 +41,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
'pageSize'
=>
2
,
)
));
$orders
=
$provider
->
get
Item
s
();
$orders
=
$provider
->
get
Model
s
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
}
...
...
@@ -52,7 +52,7 @@ class ActiveDataProviderTest extends DatabaseTestCase
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'tbl_order'
)
->
orderBy
(
'id'
),
));
$orders
=
$provider
->
get
Item
s
();
$orders
=
$provider
->
get
Model
s
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertTrue
(
is_array
(
$orders
[
0
]));
$this
->
assertEquals
(
array
(
0
,
1
,
2
),
$provider
->
getKeys
());
...
...
@@ -65,7 +65,22 @@ class ActiveDataProviderTest extends DatabaseTestCase
'pageSize'
=>
2
,
)
));
$orders
=
$provider
->
get
Item
s
();
$orders
=
$provider
->
get
Model
s
();
$this
->
assertEquals
(
2
,
count
(
$orders
));
}
public
function
testRefresh
()
{
$query
=
new
Query
;
$provider
=
new
ActiveDataProvider
(
array
(
'db'
=>
$this
->
getConnection
(),
'query'
=>
$query
->
from
(
'tbl_order'
)
->
orderBy
(
'id'
),
));
$this
->
assertEquals
(
3
,
count
(
$provider
->
getModels
()));
$provider
->
getPagination
()
->
pageSize
=
2
;
$this
->
assertEquals
(
3
,
count
(
$provider
->
getModels
()));
$provider
->
refresh
();
$this
->
assertEquals
(
2
,
count
(
$provider
->
getModels
()));
}
}
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