Yii 如何在数据库中保存数据
在用户表中,存储在db中的数据以及调整文件夹中图像的大小。 但usergallary表同样的功能不起作用,只在文件夹中调整了图像大小,而没有存储在db中Yii 如何在数据库中保存数据,yii,image-uploading,Yii,Image Uploading,在用户表中,存储在db中的数据以及调整文件夹中图像的大小。 但usergallary表同样的功能不起作用,只在文件夹中调整了图像大小,而没有存储在db中 public function actionProfileImage($id) { $userModel = User::model()->findByAttributes(array('id' => $id)); $userGallary = new UserGallary; $filePr
public function actionProfileImage($id) {
$userModel = User::model()->findByAttributes(array('id' => $id));
$userGallary = new UserGallary;
$filePrefix = Yii::app()->params['profile']['prefix'];
$targetImagePath = Yii::app()->params['profile']['image']['path'];
$target150Path = Yii::app()->params['profile']['thumb150']['path'];
$target25Path = Yii::app()->params['profile']['thumb25']['path'];
if (isset($_FILES['uploaded_picture'])) {
$handle = new Upload($_FILES['uploaded_picture']);
if ($handle->uploaded) {
$handle->file_name_body_pre = $filePrefix;
$handle->process($targetImagePath);
if ($handle->processed) {
$handle->file_name_body_pre = $filePrefix;
$handle->image_resize = true;
$handle->image_x = 150;
$handle->image_y = 150;
//$handle->image_ratio_y = true;
$handle->image_ratio = true;
$handle->process($target150Path);
if ($handle->processed) {
$handle->file_name_body_pre = $filePrefix;
$handle->image_resize = true;
$handle->image_x = 25;
$handle->image_y = 25;
// $handle->image_ratio_y = true;
$handle->image_ratio = true;
var_dump($$target150Path);exit;
$handle->process($target25Path);
if ($handle->processed) {
$userGallary->uploaded_picture = "{$filePrefix}.{$handle->file_dst_name_ext}";
$userGallary->save();
}
}
$handle->clean();
}
}
}
echo CJSON::encode( arraY('path150' => $target150Path,
'file' => $userGallary->uploaded_picture,
));
}
您是否已经使用$userGallary->save(FALSE)?检查类中的每个属性是否也有验证器。我已经尝试过$userGallary->save(FALSE);。即使图像未存储在数据库中..:(