1. Go to this page and download the library: Download lewestopher/cakephp-monga 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/ */
lewestopher / cakephp-monga example snippets
// In project_root/config/bootstrap.php:
Plugin::load('CakeMonga');
class ExampleController extends Controller
{
public function index()
{
$cake_monga = ConnectionManager::get('mongo_db');
}
}
$cake_monga = ConnectionManager::get('mongo_db');
$mongodb = $cake_monga->connect(); // An instance of the Monga Connection object
$database_list = $mongodb->listDatabases(); // We can call all of the methods on that Monga object provided by their API
class BaseCollection {
public function getCollection();
public function find($query = [], $fields = [], $findOne = false);
public function findOne($query = [], $fields = []);
public function drop();
public function listIndexes();
public function save($document, $options = []);
public function update($values = [], $query = null, $options = []);
public function insert(array $data, $options = []);
public function remove($criteria, $options = []);
public function truncate();
public function aggregate($aggregation = []);
public function distinct($key, $query = []);
public function count($query = []);
}
// Define a custom User collection at src/Model/MongoCollection/UserCollection.php.
use CakeMonga\MongoCollection\BaseCollection;
class UsersCollection extends BaseCollection
{
public function getUsersNamedJohn()
{
return $this->find(['name' => 'John']);
}
}
// We can retrieve this UsersCollection by using the static ::get() method on CollectionRegistry
use CakeMonga\MongoCollection\CollectionRegistry;
$users_collection = CollectionRegistry::get('Users');
use CakeMonga\MongoCollection\BaseCollection;
class CustomCollection extends BaseCollection
{
public function beforeFind($event, $query, $fields, $findOne);
public function beforeSave($event, $document);
public function afterSave($event, $document)
public function beforeInsert($event, $data);
public function afterInsert($event, $results)
public function beforeUpdate($event, $values, $query)
public function afterUpdate($event, $document);
public function beforeRemove($event, $criteria);
public function afterRemove($event, $result, $criteria);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.