如果只有1条记录,则将输入/选择更改为隐藏字段

时间:2015-06-18 19:49:05

标签: php cakephp

如果只有1条记录,我如何将选择更改为隐藏字段。如果只有一个分支,我希望它与该id一起隐藏,作为branch_id,作为值。

查看

    echo $this->Form->input('branch_id');

CTRL

    $this->set('branches', $this->Holiday->Branch->find('list'));

1 个答案:

答案 0 :(得分:0)

你可以试试这个,假设它返回一个数组:

if(count($branches) == 1) {
    echo $this->Form->input('branch_id', array('type' => 'hidden', 'value' => $branches['Branch'][0]['branch_id']));
}