Costum ReST路线功能视图未找到cakephp 3

时间:2017-01-17 03:17:43

标签: php rest cakephp

我尝试在cakephp 3中为ReST API构建自定义POST路由,但是当我想连接到url时,我得到了结果:

  

找不到CalculatedpricesController :: getCosts()的视图。

我的网址是这样连接到ReST:

http://localhost/test/api/calculatedprices/getCosts

这里是路线代码:

Router::scope('/', function (RouteBuilder $routes) {
    Router::prefix('api', function ($routes) {
      $routes->extensions(['json', 'xml']);
      $routes->resources('Calculatedprices', [
         'map' => [
             'getCosts' => [
                 'action' => 'getCosts',
                 'method' => 'POST'
             ]
         ]
      ]);
    });
 $routes->fallbacks(DashedRoute::class);
});

这里是控制器代码:

namespace App\Controller\Api;

use App\Controller\Api\AppController;

/**
 * Calculatedprices Controller
 *
 * @property \App\Model\Table\CalculatedpricesTable $Calculatedprices
 */
class CalculatedpricesController extends AppController
{
    public function getCosts(){
      $originIdCity = $this->request->query('originCity');
      $originIdSub = $this->request->query('originSub');
      $courierId = $this->request->query('courierId');
      $serviceId = $this->request->query('serviceId');

      $conditions = array('origin_city_id' => $originIdCity,
                      'courier_id' => $courierId,
                      'service_id' => $serviceId
                     );

     if($originIdSub == ''){
       $condition = 'origin_subdistrict_id IS NULL';
       array_push($conditions,$condition);
     } else{
       $conditions['origin_subdistrict_id'] = $originIdSub;
     }

     $calculatedprices = $this->Calculatedprices->find('all', array(
           'conditions' => $conditions
          ));

     $this->set([
        'calculatedprices' => $calculatedprices,
        '_serialize' => ['calculatedprices']
     ]);
    }
}

0 个答案:

没有答案