我正在YII的管理部分中上传图片,
为了实现这一点,我必须将其包含在模型的rules
函数中。
然而,我可以使表单正常工作的唯一方法是上传图片
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
// Other rules
array('slider_bg_image', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true),
);
}
allowEmpty
设置为true
时出现空白屏幕,但当我将其设为false
时,我被迫上传图片。
我为前端打开了错误,但后端似乎无法执行此操作。
谢谢
编辑:
<div class="row hide">
<div class="span4"><label>Slide Background Image</label></div>
<div class="span5"><?php echo $form->fileField($model,'slider_bg_image'); ?></div>
<div class="span3"><?php echo $form->error($model,'slider_bg_image'); ?></div>
</div>
答案 0 :(得分:0)
上面的代码没有错,
我只是试图在控制器中使用不存在的数据(因为图像无法上传),所以我收到了错误......
PHP致命错误:在/storage/www/mysite/core/protected/modules/admin/controllers/CustompageController.php中的非对象上调用成员函数saveAs()
所以我在控制器的条件中添加了以防止错误。