You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Paul Klimov 8032785f0d Method "\yii\mogo\Collection::buildLikeCondition()" fixed to use \MongoRegex. 11 years ago
..
file Doc comments at \yii\mongo\file\* updated. 11 years ago
ActiveQuery.php Doc comments at Mongo updated. 11 years ago
ActiveRecord.php Method "\yii\mogo\ActiveRecord::equals()" fixed. 11 years ago
ActiveRelation.php Mongo Active Record created as draft. 11 years ago
Collection.php Method "\yii\mogo\Collection::buildLikeCondition()" fixed to use \MongoRegex. 11 years ago
Connection.php Mongo File Collection added. 11 years ago
Database.php Logging and profiling at Mongo improved. 11 years ago
Exception.php Mongo Command created. 11 years ago
LICENSE.md Mongo extension created as blank. 11 years ago
Query.php Logging and profiling at Mongo improved. 11 years ago
README.md Mongo README and composer updated. 11 years ago
composer.json Mongo README and composer updated. 11 years ago

README.md

Yii 2.0 Public Preview - MongoDb Extension

Thank you for choosing Yii - a high-performance component-based PHP framework.

If you are looking for a production-ready PHP framework, please use Yii v1.1.

Yii 2.0 is still under heavy development. We may make significant changes without prior notices. Yii 2.0 is not ready for production use yet.

Build Status

This is the yii2-sphinx extension.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require yiisoft/yii2-mongo "*"

or add

"yiisoft/yii2-mongo": "*"

to the require section of your composer.json.

Note: You might have to run php composer.phar selfupdate

Usage & Documentation

This extension adds MongoDB data storage support for the Yii2 framework.

Note: extension requires MongoDB PHP Extension version 1.3.0 or higher.

To use this extension, simply add the following code in your application configuration:

return [
	//....
	'components' => [
		'mongo' => [
			'class' => '\yii\mongo\Connection',
			'dsn' => 'mongodb://developer:password@localhost:27017/mydatabase',
		],
	],
];

This extension provides ActiveRecord solution similar ot the \yii\db\ActiveRecord. To declare an ActiveRecord class you need to extend \yii\mongo\ActiveRecord and implement the collectionName and 'attributes' methods:

use yii\mongo\ActiveRecord;

class Customer extends ActiveRecord
{
	/**
	 * @return string the name of the index associated with this ActiveRecord class.
	 */
	public static function collectionName()
	{
		return 'customer';
	}

	/**
	 * @return array list of attribute names.
	 */
	public function attributes()
	{
		return ['name', 'email', 'address', 'status'];
	}
}

You can use \yii\data\ActiveDataProvider with the \yii\mongo\Query and \yii\mongo\ActiveQuery:

use yii\data\ActiveDataProvider;
use yii\mongo\Query;

$query = new Query;
$query->from('customer')->where(['status' => 2]);
$provider = new ActiveDataProvider([
	'query' => $query,
	'pagination' => [
		'pageSize' => 10,
	]
]);
$models = $provider->getModels();
use yii\data\ActiveDataProvider;
use app\models\Customer;

$provider = new ActiveDataProvider([
	'query' => Customer::find(),
	'pagination' => [
		'pageSize' => 10,
	]
]);
$models = $provider->getModels();

This extension supports MongoGridFS via classes at namespace "\yii\mongo\file".