Announcement

Collapse
No announcement yet.

Unable to get data in php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to get data in php

    client\custom\src\views\RequestManagement\list.js
    HTML Code:
    getRequestDetailsToCopy: function(oldRequestManagementId) {
                console.log('oldRequestManagementId==' + oldRequestManagementId);
                Espo.Ajax.getRequest('RequestManagement/action/getRequestlistBymanagementId', {requestManagementId: oldRequestManagementId})
                    .then(response => {
                        if (!response || response.length === 0) { // 假设期望的是一个数组,检查数组是否为空
                            console.error('未找到详细信息。Request Management ID:', oldRequestManagementId);
                            return;
                        }
                        console.log('详细信息:', response);
                    })
                    .catch(error => {
                        console.error('获取详细信息时发生错误:', error);
                        // 可选:在这里添加错误处理逻辑,如显示错误消息等
                    });
            },​
    custom\Espo\Modules\RequestManagement\Resources\ro utes.json
    HTML Code:
    [
        {
            "route": "/RequestManagement/:requestManagementId",
            "method": "get",
            "params": {
                "controller": "RequestManagement",
                "action": "getRequestlistBymanagementId"
            }
        }
    ]​
    custom\Espo\Custom\Controllers\RequestManagement.p hp
    HTML Code:
    <?php
    namespace Espo\Custom\Controllers;
    use Espo\Core\Api\Request;
    use Espo\Core\Api\Response;
    class RequestManagement extends \Espo\Core\Templates\Controllers\Base
    {
        public function actionGetRequestlistBymanagementId(Request $request, Response $response)
        {
            // 使用 Request 对象获取路由参数
            $requestManagementId = $request->getRouteParam('requestManagementId');
            // 检查参数是否存在
            if (empty($requestManagementId)) {
                throw new \Espo\Core\Exceptions\BadRequest("The 'requestManagementId' parameter is missing.");
            }
            // 获取实体管理器并查询详情
            $entityManager = $this->getEntityManager();
            $details = $entityManager->getRepository('RequestDetail')->where([
                'requestManagementId' => $requestManagementId
            ])->find();
            // 如果没有找到任何详情,返回空数组
            if (!$details) {
                $response->setStatus(404); // 设置适当的HTTP状态码
                return [];
            }
            // 将详情转换为数组形式返回
            $result = [];
            foreach ($details as $detail) {
                $result[] = $detail->toArray();
            }
            // 使用 Response 对象设置返回数据
            $response->setJsonContent($result);
            return $result;
        }
    }
    ​​
    In the following code I cannot get the requestManagementId data
    $requestManagementId = $request->getRouteParam('requestManagementId');​​
    Attached Files
Working...
X