0

在 abeforeMarshall()中,我在我的实体中创建了一个附加字段。在我的控制器中,debug($myEntity)在将数据分配给视图之前,我看到了我的字段。我什至创建了一个像下面这样的吸气剂:

protected function _getTmpImage() {

    if (isset($this->_properties['tmp_image'])) {
        debug($this->_properties['tmp_image']);
        return $this->_properties['tmp_image'];
    } else {
        return null;
    }
}

在我看来,我看到了相应的debug()显示。

但是下面一行:

<?= $this->Form->hidden('agpoi_images.'.$key.'.tmp_image'); ?>

拼命创建以下html代码:

<input name="agpoi_images[0][tmp_image]" class="form-control" value="" type="hidden">

你能告诉我为什么吗?

PS:我也尝试在我的实体类中添加以下语句,即使我认为根据文档我不必这样做

class MyEntity extends Entity
{

    protected $_virtual = ['tmp_image'];

}
4

1 回答 1

0

在视图文件中,当使用表单元素时,$fieldname必须是“Modelname.fieldname”的形式,这使得 cakephp 很容易替换控制器数据并以这种格式发送 post 请求。

$this->Form->hidden(‘MyEntity.tmp_image)在您的情况下,您可以以与显示为相同的方式创建隐藏的表单字段

<input name=“MyEntity[tmp_image]" class="form-control" value=“&lt;tmp_image_value>" type="hidden">
于 2017-05-27T12:24:23.263 回答