Laravel Json 响应函数


Laravel Json response function

我目前正在Laravel(v4.2.11)中开发一个使用ExtJS(v4.2.1-gpl)的应用程序。

作为我的 ExtJS

应用程序的一部分,我正在开发一个由 ExtJS 使用的 JSON 响应。但是,我想做以下事情:

return Response::json(array(
  'menusystem' => array(
    'listeners' => array(
      'click' => function() {
        location.href = 'test'
      }
    )
  )
);

我知道这不是有效的 JSON。但是,这就是应用程序的先前开发人员的方式。我想知道这在PHP,Laravel或JSON中是否可行。

你可以做这样的事情

$response = array(
  'menusystem' => array(
    'listeners' => array(
      'click' => "%%%function() {
        location.href = 'test'
      }%%%"
    )
  )
);
$response = json_encode($response);
$response = str_replace('"%%%', '', $response);
$response = str_replace('%%%"', '', $response);
return $response;

这只是一般概念。您可以在特殊宏等中检测功能结构。