##### Table of Contents
- Description
- Requirements
- Installing the PHP client
- Using Composer
- Cloning the git repository
- How to use the Cakephp ArangoDb Client
- Setting up the connection options
- Models
- Controllers
This is the cakephp version of the arangodb-php lib. the cakephp client allows you to convert your models to arangodb supported models easily. the cakephp arangodb client also allows you to use cakephp find, save, delete, update and joins etc simillar to cake core functionality.
-
Cakephp version 3.0 or higher
-
ArangoDB database server version 3.0 or higher.
-
PHP version 5.6 or higher
Note on PHP version support:
To get started you need PHP 5.6 or higher plus an ArangoDB server running on any host that you can access.
There are two alternative ways to get the Cakephp ArangoDb client:
- Using Composer
- Cloning the git repository
composer require cakephparangodb/arangodb
NOTE IF ANY ERROR THEN Add minimum-stability and prefer-stable to your composer.json
Example
{
"minimum-stability": "dev",
"prefer-stable": true
}
You need to have a git client installed. To clone this repository from github, execute the following command in your project directory:
git clone "https://github.com/shubham715/Cakephp-ArangoDb-Package.git"
This will create a subdirectory arangodb-php in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files. To invoke this autoloader, add the following line to your PHP files that will use the library:
If you do not wish to include autoload.php to load and setup the autoloader, you can invoke the autoloader directly:
require 'cakephparangodb/lib/ArangoDBClient/autoloader.php';
\ArangoDBClient\Autoloader::init();
In order to use Cakephp ArangoDB, you need to specify the connection options. currently its only available from core files of this client in future updates we will add functionality to change db config from app.php
For now you need to open yourProject/vendor/cakephparangodb/arangodb/lib/ArangoDBClient/Connect.php and change db config of $_options according to your db config.
Convert Cakephp Models to ArangoDb supported models. Change your cakephp models to like below example
Here for example i am changing UsersTable Model.
<?php
namespace App\Model\Table;
use ArangoDBClient\Connect;
class UsersTable extends \ArangoDBClient\Eloquent\Model
{
}
?>
Thats it. Now you can load model in your controller by using loadModel and use users Table of arangodb into controller like below example
##Here i am giving some examples that how you can use models in controller##FIND QUERY
$data = $this->Users->find('all');
$data = $this->Users->find('all',['conditions'=>['name'=>'test','email'=>'test@gmail.com']]);
$data = $this->Users->findById(10);
$data = $this->Users->find('all',['select'=>['name','email','status']]);
$data = $this->Users->findOne('all',['conditions'=>['email'=> $email]]);
$data = $this->Users->find('all',['select'=>['name','email','status']]);
$data = $this->Users->find('all', ['conditions'=>['email'=>'test@gmail.com'],'order'=>['paydate'=> 'ASC'],'select'=>['name','email','status']]);
$data = $this->Users->isUnique(['conditions'=>['email'=> $email]]);
$data = $this->Users->count(['conditions'=>['email'=> $email]]);
##Updation
$data = $this->Users->updateById(['email'=> $email],['id'=> 1]);
$data = $this->Users->updateAll(['email'=> $email],['id'=> 1]);
##deletion
deleteById
$data = $this->Users->deleteById(1);
deleteAll
$data = $this->Users->deleteAll(['email'=> $email]);
$data = $this->Users->createOrUpdate(['email'=> $email,'id'=> 10]);
$data = $this->Users->findWithJoin('all',['contain'=> 'userdetails', 'conditions'=>['c.userid'=> 'u.id']]);
//Here c is refer for base table and u is for join table.
##Save Data
$data = ['name'=>'shubham715', email'=> 'shubhamsharma715@gmail.com', 'status'=> 1];
$saveData = $this->Users->save($financeEntity);
Here lots of examples that we will update soon.