CAKEPHP3传入json复选框

CAKEPHP3传入json复选框,php,json,cakephp,Php,Json,Cakephp,我正在开发cakephpv3。我面临一个问题。 我想显示复选框的循环,但我得到的数据是json格式的 控制器 public function add() { $building = $this->Buildings->newEntity(); if ($this->request->is('post')) { $building = $this->Buildings->patchEntity($buil

我正在开发
cakephpv3
。我面临一个问题。 我想显示复选框的循环,但我得到的数据是json格式的

控制器

 public function add() {
        $building = $this->Buildings->newEntity();
        if ($this->request->is('post')) {
            $building = $this->Buildings->patchEntity($building, $this->request->data);
            if ($this->Buildings->save($building)) {
                $this->Flash->success(__('The building has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The building could not be saved. Please, try again.'));
            }
        }
        $countries = $this->Buildings->Countries->find('list');
        $this->loadModel("Amenities");
        $amenities = $this->Amenities->find('All');
        $this->set(compact('building', 'countries','amenities'));
        $this->set('_serialize', ['building','amenities']);
    }
查看

  foreach ($amenities as $key => $value) {
                   echo $this->Form->control($value, ['type' => 'checkbox']);
                }
输出是

我希望以以下方式输出

Amenities

[checkbox] [checkboxname] [fa-icon] 

[checkbox] [checkboxname] [fa-icon]

[checkbox] [checkboxname] [fa-icon]
// so on
我怎样才能做到这一点

我可以通过以下代码设置选项

 echo $this->Form->input('country_id', ['options' => $countries, 'empty' => 'Select country']);

控件的第一个参数是字段名。您正在传入一个实体,它正在以它知道的最佳方式将其转换为字符串。您可能打算使用
$value->name

使用
$data=json\u decode($your\u json\u string,TRUE)
它将返回数组,然后您可以根据需要迭代数组。是的,我可以使用
json\u decode
但是我正在寻找任何默认的
cakephp
方式,就像我用于
selectbox
一样。请相应地更新您的问题。显然,请指定您已经尝试过的内容和您正在寻找的内容。我已经提到,我曾经尝试过以下代码
foreach($key=>value){echo$this->Form->control($value,['type'=>'checkbox']);}
我没有看到任何一行指定您希望以cakephp的方式进行操作。