ProjectController.php 1.31 KB
<?php
/**
 * Created by PhpStorm.
 * User: Alex Savenko
 * Date: 06.02.2017
 * Time: 19:06
 */

namespace App\Controllers;

use PhalconRest\Mvc\Controllers\CrudResourceController;


class ProjectController extends CrudResourceController {

    public function test_post() {

        $response = [
            'test' => '123'
        ];

        return $response;

    }

    public function test_get($id)
    {



        $item = $this->getFindData($id);
        return $this->getModelPrimaryKey();

        return 'breakpoint';
        if (!$item) {
            return $this->onItemNotFound($id);
        }

        if (!$this->findAllowed($id, $item)) {
            return $this->onNotAllowed();
        }

        $response = $this->getFindResponse($item);

        return '123';
    }

    protected function getFindData($id)
    {
        $phqlBuilder = $this->phqlQueryParser->fromQuery($this->query, $this->getResource());

        $phqlBuilder
            ->andWhere('[' . $this->getResource()->getModel() . '].' . 'id = '.$id);

        $this->modifyReadQuery($phqlBuilder);
        $this->modifyFindQuery($phqlBuilder, $id);

        $results = $phqlBuilder->getQuery()->execute();

        return count($results) >= 1 ? $results->getFirst() : null;
    }

    protected function getModelPrimaryKey()
    {
        return 'id';
    }

}