dsgd4654674 2018-06-17 09:37 采纳率: 0%
浏览 72

如何调试“”无法在非对象上获取属性。“在自定义操作中?

I'm getting the error

"hydra:description": "Unable to get a property on a non-object.",

when trying to implement a custom operation. I'm trying to figure out what causes this problem and while I've found a dozen or so wild guesses on both stackoverflow and elsewhere, none of the solutions posted there work for me.

I'm trying to figure out how to debug this problem. The trace and info included with the error message is less than helpful:

{
  "@context": "/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Unable to get a property on a non-object.",
  "trace": [
    {
      "namespace": "",
      "short_class": "",
      "class": "",
      "type": "",
      "function": "",
      "file": "/Users/tom/Code/api-platform/vendor/symfony/expression-language/Node/GetAttrNode.php",
      "line": 73,
      "args": []
    },
    {
      "namespace": "Symfony\\Component\\ExpressionLanguage\\Node",
      "short_class": "GetAttrNode",
      "class": "Symfony\\Component\\ExpressionLanguage\\Node\\GetAttrNode",
      "type": "->",
      "function": "evaluate",
      "file": "/Users/tom/Code/api-platform/vendor/symfony/expression-language/Node/GetAttrNode.php",
      "line": 71,
      "args": [
        [
          "array",
          {
            "constant": [
              "array",
              {
                "compiler": [
                  "object",
                  "Closure"
                ],
                "evaluator": [
                  "object",
                  "Closure"
                ]
              }
            ],
            "is_granted": [
              "array",
              {
                "compiler": [
                  "object",
                  "Closure"
                ],
                "evaluator": [
                  "object",
                  "Closure"
                ]
              }

all of which tells me absolutely nothing about which property on which object it is looking for, what data it is inspecting, and where I should be looking for the problem.

I've tried adding var_dump() statements into both my own code and places like before line 73 in GetAttrNode.php and it doesn't help. It appears that the code does not even hit my controller. I'm fairly certain that the problem isn't in my controller, as at this point the controller is nothing but the stub as described in the documentation (https://api-platform.com/docs/core/operations#creating-custom-operations-and-controllers).

How can I debug this issue and figure out where the problem is?

  • 写回答

1条回答 默认 最新

  • dongzaotiao2863 2018-06-20 21:01
    关注

    According to the stack trace you provided, the error is in your security rule. Check the value of the is_granted attribute in your class marked with the @ApiResource annotation, it has some kind of errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM