我有更新记录的情况而不替换Yii中的文件路径。无论我做什么,它总是在数据库中清空我的文件路径字段。这是我在控制器中的代码
if(isset($_POST['Band']))
{
$model->attributes = $_POST['Band'];
$myfile = CUploadedFile::getInstance($model,'logo');
if($model->save())
{
if(!empty($myfile))
{
$path = explode(".", $myfile->name);
$filePath = 'files/'.$myfile->name;
$myfile->saveAs($filePath);
}
$this->redirect(array('view','id'=>$model->band_id));
}
}
这是我到目前为止所做的,但仍然将数据库更新中的徽标归档为null。
答案 0 :(得分:0)
试试这段代码,它适合你 -
array('logo', 'file', 'types'=>'jpg, jpeg, bmp, gif, png', 'allowEmpty'=>true, 'on'=>'insert, update')
在模型规则数组中定义此 -
$sql = "SELECT Email FROM table GROUP BY Email having (sum(payment = 'paid')) = 0";
$sql = "SELECT count(DISTINCT Email) from table WHERE payment='paid'";
$sql = "SELECT count(DISTINCT Email) from table";