dsaaqdz6223 2017-01-17 03:17
浏览 16

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

i try to build a custom POST route for ReST API in cakephp 3, but when i want to connect to the url i got result:

The view for CalculatedpricesController::getCosts() was not found.

My url to connect to ReST like this :

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

here's the route code:

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);
});

here's the controller code:

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)