<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
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号