mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-09 17:57:38 +08:00
Docs for Sphinx extension updated.
This commit is contained in:
@ -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()]].
|
||||||
|
|||||||
@ -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();
|
||||||
```
|
```
|
||||||
@ -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
|
|||||||
|
|
||||||
// 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([
|
||||||
|
|||||||
Reference in New Issue
Block a user