我想在输入字段中添加一个数组条件。如果flag == 1
是必填字段,否则不是必填字段
<?php echo $this->Form->input('course_workbook_answer_file', array(
'type' => 'file',
'label' => false,
'id' => 'course_workbook_answer_file',
'class' => 'form-control',
'name' => 'data[CourseWorkbook][0][course_workbook_answer_file]',
$port_flag == 0 ? 'required' => 'required' : Null
)); ?>
答案 0 :(得分:0)
您应该将条件更改为值,而不是完整的索引。
<?php echo $this->Form->input('course_workbook_answer_file', array(
'type' => 'file',
'label' => false,
'id' => 'course_workbook_answer_file',
'class' => 'form-control',
'name' => 'data[CourseWorkbook][0][course_workbook_answer_file]',
'required' => ($port_flag==0)?'required':Null,
)); ?>