我正在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>I am uploading images in a form in an admin section in YII,
To get this working I must include it in the rules function in the model.
However the only way I can get the form working is to upload an image
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), ); }I get a blank screen when allowEmpty is set to true, but when I have it as false I am forced to upload the image.
I have errors turned on for the front end ,but cannot seem to do so for the backend.
Thank you
EDIT:
<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>最满意答案
上面的代码没有错,
我只是试图在控制器中使用不存在的数据(因为图像无法上传),所以我收到错误...
PHP致命错误:在/storage/www/mysite/core/protected/modules/admin/controllers/CustompageController.php中的非对象上调用成员函数saveAs()
所以我添加了控制器中的条件以防止错误。
There was nothing wrong with the code above,
I was simply attempting to use data in the controller that didnt exist (as an image wouldnt be uploaded), so I was receiving the error...
PHP Fatal error: Call to a member function saveAs() on a non-object in /storage/www/mysite/core/protected/modules/admin/controllers/CustompageController.php
So I added in conditions in the controller to prevent the error.
更多推荐
发布评论