Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3996c799
Commit
3996c799
authored
Jul 09, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow customizing DB connection for ActiveDataProvider.
parent
ad2d1881
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
2 deletions
+25
-2
ActiveDataProvider.php
framework/yii/data/ActiveDataProvider.php
+25
-2
No files found.
framework/yii/data/ActiveDataProvider.php
View file @
3996c799
...
...
@@ -7,9 +7,11 @@
namespace
yii\data
;
use
Yii
;
use
yii\base\InvalidConfigException
;
use
yii\db\Query
;
use
yii\db\ActiveQuery
;
use
yii\db\Connection
;
/**
* ActiveDataProvider implements a data provider based on [[Query]] and [[ActiveQuery]].
...
...
@@ -52,12 +54,33 @@ class ActiveDataProvider extends DataProvider
* @see getKeys()
*/
public
$key
;
/**
* @var Connection|string the DB connection object or the application component ID of the DB connection.
* If not set, the default DB connection will be used.
*/
public
$db
;
private
$_items
;
private
$_keys
;
private
$_count
;
/**
* Initializes the DbCache component.
* This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
* @throws InvalidConfigException if [[db]] is invalid.
*/
public
function
init
()
{
parent
::
init
();
if
(
is_string
(
$this
->
db
))
{
$this
->
db
=
Yii
::
$app
->
getComponent
(
$this
->
db
);
if
(
!
$this
->
db
instanceof
Connection
)
{
throw
new
InvalidConfigException
(
'The "db" property must be a valid DB Connection application component.'
);
}
}
}
/**
* Returns the number of data items in the current page.
* This is equivalent to `count($provider->items)`.
* When [[pagination]] is false, this is the same as [[totalItemCount]].
...
...
@@ -88,7 +111,7 @@ class ActiveDataProvider extends DataProvider
throw
new
InvalidConfigException
(
'The "query" property must be an instance of Query or its subclass.'
);
}
$query
=
clone
$this
->
query
;
$this
->
_count
=
$query
->
limit
(
-
1
)
->
offset
(
-
1
)
->
count
();
$this
->
_count
=
$query
->
limit
(
-
1
)
->
offset
(
-
1
)
->
count
(
'*'
,
$this
->
db
);
}
return
$this
->
_count
;
}
...
...
@@ -121,7 +144,7 @@ class ActiveDataProvider extends DataProvider
if
((
$sort
=
$this
->
getSort
())
!==
false
)
{
$this
->
query
->
orderBy
(
$sort
->
getOrders
());
}
$this
->
_items
=
$this
->
query
->
all
();
$this
->
_items
=
$this
->
query
->
all
(
$this
->
db
);
}
return
$this
->
_items
;
}
...
...
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