douli8040 2016-10-05 13:24
浏览 44
已采纳

控制器属性不能包含非标量\ /非空值

I would like to provide my controller object like this with hinclude.js :

{{ render_hinclude(controller("AppBundle:Default:Test"), { 'object': my_object }) }}

Unfortunately I got this error:

"An exception has been thrown during the rendering of a template (\"Controller attributes cannot contain non-scalar/non-null values (value for key \"my_object\" is not a scalar or null).\")

Can you help me ?

Thanks in advance !

  • 写回答

2条回答 默认 最新

  • douan2478 2016-10-05 17:38
    关注

    The exception is right, only scalar/null values are allowed to pass for controller attributes when render_hinclude() is used, because is needed to generate a valid fragment URI from them.


    Why?

    Suppose you try to pass this entity with private properties, when it comes to generate the URI for this parameter happens the following:

    var_dump(http_build_query(array('object' => $my_object)))
    
    // output: 
    // string(0) ""
    

    http://php.net/manual/en/function.http-build-query.php#refsect1-function.http-build-query-parameters

    If query_data is an object, then only public properties will be incorporated into the result.


    BTW the statement that you provided is not valid, you should pass this attribute to controller(...) function, something like this:

    {{ render_hinclude(controller("AppBundle:Default:test", {'id': my_object.id })) }}
    

    Then, your controller should have the scalar value id and get the corresponding object. However, use the argument resolver feature to avoid this step:

    public function testAction(Object $object) {...}
    

    Next:

    {{ render_hinclude(controller("AppBundle:Default:test", {'object': my_object.id })) }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch