1. Go to this page and download the library: Download yiicod/mongoyii library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class User extends EMongoDocument{
function collectionName(){
return 'users';
}
public static function model($className=__CLASS__){
return parent::model($className);
}
}
class User extends EMongoDocument{
/** @virtual */
public $agree = 1;
public $addresses = array();
function collectionName(){
return 'users';
}
public static function model($className=__CLASS__){
return parent::model($className);
}
}
$c = new EMongoCriteria();
User::model()->find($c
->addCondition(array('name' => 'sammaye')) // This is basically a select
->addOrCondition(array(array('interest' => 'Drinking'), array('interest' => 'Clubbing'))) // This is adding a $or condition to our select
->skip(2) // This skips a number of rows
->limit(3) // This limits by a number of rows
);
class versioned extends EMongoDocument{
public function versioned(){
return true;
}
public function versionField(){
return '_v'; // This is actually the default value in EMongoDocument
}
public static function model($className=__CLASS__){
return parent::model($className);
}
}
'components'=>array(
...
'cache' => array(
'class'=>'application.extensions.MongoYii.util.EMongoCache',
// 'ensureIndex' => true, //set to false after first use of the cache
// 'mongoConnectionId' => 'mongodb',
// 'collectionName' => 'mongodb_cache',
),
}
// flush cache
Yii::app()->cache->flush();
// add data to cache
Yii::app()->cache->set('apple', 'fruit');
Yii::app()->cache->set('onion', 'vegetables');
Yii::app()->cache->set(1, 'one');
Yii::app()->cache->set(2, 'two');
Yii::app()->cache->set('one', 1);
Yii::app()->cache->set('two', 2);
// delete from cache
Yii::app()->cache->delete(1);
Yii::app()->cache->delete('two');
// read from cache
echo Yii::app()->cache->get(2);
// multiple read from cache
$arr = Yii::app()->cache->mget(array('apple', 1, 'two'));
print_r($arr); // Array( [apple] => fruit [1] => [two] => )