<code class="lang-php"> public function actionRegister() { $registerForm = new RegisterForm(); if (isset($_POST['RegisterForm'])) { $registerForm->attributes = $_POST['RegisterForm']; $registerForm->avatar = CUploadedFile::getInstance($registerForm, 'avatar'); if ($registerForm->avatar) { $preRand = time() . mt_rand(0, 99999); $imageName='img_big'.$preRand.$registerForm->avatar->extensionName; $registerForm->avatar->saveAs('uploads/' . $imageName); $registerForm->avatar = $imageName; } $path = dirname(Yii::app()->BasePath) . '/uploads/'; $thumb = Yii::app()->thumb; //与 $thumb=new Cthumb()有什么区别? $thumb->image = $path . 'img_small' . $preRand . $registerForm->avatar->extensionName; $thumb->width = 130; $thumb->height = 95; $thumb->mode = 4; $thumb->directory = $path; $thumb->defaultName = $preRand; $thumb->createThumb(); $thumb->save(); $registerForm->thumb = $thumb->image; $registerForm->registerDate = time(); //save方法会自动验证 if ($registerForm->save() && $registerForm->login()) { Yii::app()->db->getLastInsertID(); //取得插入的Id。但是 } } </code>
这个RegisterForm是继承的CFormModel,怎么还可以调用save方法?
而且我看了源代码CFormModel跟CActiveRecord没有关系啊。。
<code class="lang-php"> public function actionRegister() { $registerForm = new RegisterForm(); if (isset($_POST['RegisterForm'])) { $registerForm->attributes = $_POST['RegisterForm']; $registerForm->avatar = CUploadedFile::getInstance($registerForm, 'avatar'); if ($registerForm->avatar) { $preRand = time() . mt_rand(0, 99999); $imageName='img_big'.$preRand.$registerForm->avatar->extensionName; $registerForm->avatar->saveAs('uploads/' . $imageName); $registerForm->avatar = $imageName; } $path = dirname(Yii::app()->BasePath) . '/uploads/'; $thumb = Yii::app()->thumb; //与 $thumb=new Cthumb()有什么区别? $thumb->image = $path . 'img_small' . $preRand . $registerForm->avatar->extensionName; $thumb->width = 130; $thumb->height = 95; $thumb->mode = 4; $thumb->directory = $path; $thumb->defaultName = $preRand; $thumb->createThumb(); $thumb->save(); $registerForm->thumb = $thumb->image; $registerForm->registerDate = time(); //save方法会自动验证 if ($registerForm->save() && $registerForm->login()) { Yii::app()->db->getLastInsertID(); //取得插入的Id。但是 } } </code>
这个RegisterForm是继承的CFormModel,怎么还可以调用save方法?
而且我看了源代码CFormModel跟CActiveRecord没有关系啊。。
CFormModel并没有实现save方法,见文档:http://www.yiiframework.com/doc/api/1.1/CFormModel