Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokil/php-mongo-yii
Yii 1 PHPMongo Adapter. Part of @PHPMongoKit
https://github.com/sokil/php-mongo-yii
mongo mongodb odm php phpmongo phpmongokit yii yii-adapter
Last synced: 17 days ago
JSON representation
Yii 1 PHPMongo Adapter. Part of @PHPMongoKit
- Host: GitHub
- URL: https://github.com/sokil/php-mongo-yii
- Owner: sokil
- License: mit
- Created: 2014-08-29T20:29:16.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-16T09:07:23.000Z (almost 7 years ago)
- Last Synced: 2024-11-14T18:45:28.833Z (about 1 month ago)
- Topics: mongo, mongodb, odm, php, phpmongo, phpmongokit, yii, yii-adapter
- Language: PHP
- Homepage: http://phpmongokit.github.io/
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
php-mongo-yii
=============Yii 1 Adapter for [PHPMongo ORM](https://github.com/sokil/php-mongo)
Installation
------------You can install library through Composer:
```javascript
{
"require": {
"sokil/php-mongo-yii": "dev-master"
}
}
```Configuration of Client
-----------------------```php
array(
// configure mongo service
'mongo' => array(
'class' => '\Sokil\Mongo\Yii\ClientAdapter',
'dsn' => 'mongodb://127.0.0.1',
'options' => array(
'connect' => true,
'readPreference' => \MongoClient::RP_SECONDARY_PREFERRED,
),
'defaultDatabase' => 'database_name',
'map' => array(
'database_name' => array(
'collectionName1' => '\Collection\Class1',
'collectionName2' => '\Collection\Class2',
)
),
'logger' => 'somePsrCompartibleLogService',
),
),
// define log
'somePsrCompartibleLogService' => array(
'class' => '\SomePSRLogger',
),
);
```For PSR compartible logger you can use adapter to Yii's log https://gist.github.com/sokil/56654a5abdfbcce411ea or [Monolog](https://github.com/Seldaek/monolog)
Using mongo in code:
```php
mongo->getClient();
// get database
$database = \Yii::app()->mongo->getDatabase('database_name');
// get collection of default database
$collection = \Yii::app()->mongo->getCollection('collectionName1');
```Routing Yii logs to mongo
-------------------------Configure logger to use mongo:
```php
array(
// define connection service
'mongo' => array(
'class' => '\Sokil\Mongo\Yii\ClientAdapter',
// ...
),
// configure log service
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => '\Sokil\Mongo\Yii\LogRoute',
'levels' => 'error, warning',
// define collection name where to store log records
'collectionName' => 'log',
// define mongo connection service used to record logs
'serviceName' => 'mongo',
),
),
),
),
);
```Data Provider
-------------```php
mongo->getCollection('collName')->find()->where('type', 10);// get data provider
$dataProvider = new \Sokil\Mongo\Yii\DataProvider($cursor, array(
'attributes' => array('name', 'type'),
'pagination' => array('pageSize' => 30)
));
```