PHP code example of qeti / yii2-podata-adapter

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

    

qeti / yii2-podata-adapter example snippets


    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                ['class' => 'qeti\Yii2PODataAdapter\ODataUrlRule'],
            ],
        ],
    ],
    'controllerMap' => [
        'o-data' => 'qeti\Yii2PODataAdapter\implementation\ODataController',
    ],


yii::$classMap['qeti\Yii2PODataAdapter\implementation\MetadataProvider'] = '@app/models/OData/MetadataProvider.php';

namespace app\models\OData\Entities;

use yii\db\ActiveRecord;
use qeti\SimplePOData\EntityTrait;

class Request extends ActiveRecord {

    use EntityTrait;

    public $id;
    public $type_code;
    public $status_code;
}

namespace qeti\Yii2PODataAdapter\implementation;

use POData\Providers\Metadata\Type\EdmPrimitiveType;
use POData\Providers\Metadata\SimpleMetadataProvider;

class MetadataProvider
{
    const MetaNamespace = "Data";

    /**
     * @return IMetadataProvider
     */
    public static function create()
    {
        $metadata = new SimpleMetadataProvider('Data', self::MetaNamespace);

        $requestEntityType = self::createRequestEntityType($metadata);
        $requestResourceSet = $metadata->addResourceSet('Requests', $requestEntityType);

        return $metadata;
    }

    private static function createRequestEntityType(SimpleMetadataProvider $metadata)
    {
        $et = $metadata->addEntityType(new \ReflectionClass('app\models\OData\Entities\Request'), 'Requests', self::MetaNamespace);
        $metadata->addKeyProperty($et, 'id', EdmPrimitiveType::INT64); 
        $metadata->addPrimitiveProperty($et, 'type_code', EdmPrimitiveType::STRING);
        $metadata->addPrimitiveProperty($et, 'status_code', EdmPrimitiveType::STRING);
        return $et;
    }

}