Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected function beforeValidate()
- {
- $this->uploadFiles();
- if ($this->hasAttribute('author') && empty($this->author))
- $this->author = Yii::app()->user->id;
- return parent::beforeValidate();
- }
- protected function uploadFiles()
- {
- foreach ($this->rules() as $rule) {
- if (in_array("file", $rule)) {
- $attributes = explode(",", $rule[0]);
- foreach ($attributes as $attribute) {
- $image = CUploadedFile::getInstance($this, $attribute);
- if (is_object($image)) {
- $filename = md5(rand(1, 99999) . $image) . $image;
- $image->saveAs('images/site/manufacturers/' . $filename);
- $this->$attribute = 'images/site/manufacturers/' . $filename;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment