PHP code example of explosivebit / yii2-arangodb

1. Go to this page and download the library: Download explosivebit/yii2-arangodb 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/ */

    

explosivebit / yii2-arangodb example snippets


return [
    //....
    'components' => [
        'arangodb' => [
            'class' => '\explosivebit\arangodb\Connection',
            'connectionOptions' => [
                ArangoDBClient\ConnectionOptions::OPTION_DATABASE => "mydatabase",
                ArangoDBClient\ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529',
                ArangoDBClient\ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
                //ArangoDBClient\ConnectionOptions::OPTION_AUTH_USER   => '',
                //ArangoDBClient\ConnectionOptions::OPTION_AUTH_PASSWD => '',
            ],
        ],
    ],
];

use explosivebit\arangodb\Query;

$query = new Query;
// compose the query
$query->select(['name', 'status'])
    ->from('customer')
    ->limit(10);
// execute the query
$rows = $query->all();

use explosivebit\arangodb\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 ['_key', 'name', 'email', 'address', 'status'];
    }
}

use yii\data\ActiveDataProvider;
use explosivebit\arangodb\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();

return [
    // ...
    'controllerMap' => [
        'arangodb-migrate' => 'explosivebit\arangodb\console\controllers\MigrateController'
    ],
];

class m170413_210957_create_services_collection extends \explosivebit\arangodb\Migration
{
    public function up()
    {
        # When you start the migration, a collection of "services" with the edge type is created
        $this->createCollection('services',['Type' => 3]);
    }

    public function down()
    {
        # When the migration rollback starts, the collection "services"
        $this->dropCollection('services');
    }
}

return [
    'bootstrap' => ['debug'],
    'modules' => [
        'debug' => 'yii\debug\Module',
        'panels' => [
            'arango' => [
                'class' => 'explosivebit\arangodb\panels\arangodb\ArangoDbPanel',
            ],
        ],
        ...
    ],
    ...
];

php composer.phar