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
400b5310
Commit
400b5310
authored
Nov 22, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs for Sphinx extension updated.
parent
01c269a9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
1 deletion
+75
-1
ActiveRecord.php
extensions/sphinx/ActiveRecord.php
+1
-1
README.md
extensions/sphinx/README.md
+50
-0
ActiveDataProviderTest.php
tests/unit/extensions/sphinx/ActiveDataProviderTest.php
+24
-0
No files found.
extensions/sphinx/ActiveRecord.php
View file @
400b5310
...
@@ -35,7 +35,7 @@ use Yii;
...
@@ -35,7 +35,7 @@ use Yii;
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
ActiveRecord
extends
Model
abstract
class
ActiveRecord
extends
Model
{
{
/**
/**
* @event Event an event that is triggered when the record is initialized via [[init()]].
* @event Event an event that is triggered when the record is initialized via [[init()]].
...
...
extensions/sphinx/README.md
View file @
400b5310
...
@@ -66,4 +66,53 @@ return [
...
@@ -66,4 +66,53 @@ return [
],
],
],
],
];
];
```
This extension provides ActiveRecord solution similar ot the
[
[\yii\db\ActiveRecord
]
].
To declare an ActiveRecord class you need to extend
[
[\yii\sphinx\ActiveRecord
]
] and
implement the
`indexName`
method:
```
php
use
yii\sphinx\ActiveRecord
;
class
Article
extends
ActiveRecord
{
/**
* @return string the name of the index associated with this ActiveRecord class.
*/
public
static
function
indexName
()
{
return
'idx_article'
;
}
}
```
You can use
[
[\yii\data\ActiveDataProvider
]
] with the
[
[\yii\sphinx\Query
]
] and
[
[\yii\sphinx\ActiveQuery
]
]:
```
php
use
yii\data\ActiveDataProvider
;
use
yii\sphinx\Query
;
$query
=
new
Query
;
$query
->
from
(
'yii2_test_article_index'
)
->
match
(
'development'
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'pagination'
=>
[
'pageSize'
=>
10
,
]
]);
$models
=
$provider
->
getModels
();
```
```
php
use
yii\data\ActiveDataProvider
;
use
app\models\Article
;
$provider
=
new
ActiveDataProvider
([
'query'
=>
Article
::
find
(),
'pagination'
=>
[
'pageSize'
=>
10
,
]
]);
$models
=
$provider
->
getModels
();
```
```
\ No newline at end of file
tests/unit/extensions/sphinx/ActiveDataProviderTest.php
View file @
400b5310
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
yiiunit\extensions\sphinx
;
namespace
yiiunit\extensions\sphinx
;
use
yii\data\ActiveDataProvider
;
use
yii\data\ActiveDataProvider
;
use
yii\sphinx\Query
;
use
yiiunit\data\sphinx\ar\ActiveRecord
;
use
yiiunit\data\sphinx\ar\ActiveRecord
;
use
yiiunit\data\sphinx\ar\ArticleIndex
;
use
yiiunit\data\sphinx\ar\ArticleIndex
;
...
@@ -19,6 +20,29 @@ class ActiveDataProviderTest extends SphinxTestCase
...
@@ -19,6 +20,29 @@ class ActiveDataProviderTest extends SphinxTestCase
// Tests :
// Tests :
public
function
testQuery
()
{
$query
=
new
Query
;
$query
->
from
(
'yii2_test_article_index'
);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'db'
=>
$this
->
getConnection
(),
]);
$models
=
$provider
->
getModels
();
$this
->
assertEquals
(
2
,
count
(
$models
));
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'db'
=>
$this
->
getConnection
(),
'pagination'
=>
[
'pageSize'
=>
1
,
]
]);
$models
=
$provider
->
getModels
();
$this
->
assertEquals
(
1
,
count
(
$models
));
}
public
function
testActiveQuery
()
public
function
testActiveQuery
()
{
{
$provider
=
new
ActiveDataProvider
([
$provider
=
new
ActiveDataProvider
([
...
...
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