小编Nik*_*vic的帖子

symfony 3控制器中的自定义注释

所以问题非常简单.我的控制器中的代码已经变得冗余,我决定为它做一个注释.

if (!$request->getContentType() === 'json' ) {
        return new JsonResponse(array('success' => false));
    }
    $content = $request->getContent();

    if(empty($content)){
        throw new BadRequestHttpException("Content is empty");
    }
    $data = json_decode($content, true);
    if(empty($data) || !array_key_exists('type', $data)) {
        return new JsonResponse(array('success' => false));
    }
Run Code Online (Sandbox Code Playgroud)

如何制作自定义注释@CheckRequest,我可以使用$ request对象作为参数?

php doctrine annotations symfony

10
推荐指数
1
解决办法
3755
查看次数

标签 统计

annotations ×1

doctrine ×1

php ×1

symfony ×1