Created
November 9, 2012 14:47
-
-
Save jamband/4046096 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ItemController extends Controller | |
{ | |
... | |
/** | |
* Creates a new item. | |
*/ | |
public function actionCreate1() | |
{ | |
$model = new Item(); | |
if (isset($_POST['Item'])) | |
{ | |
$model->attributes = $_POST['Item']; | |
if ($file = CUploadedFile::getInstance($model, 'image')) | |
$model->image = $this->uniqId.'.'.$file->extensionName; | |
if ($model->save()) | |
{ | |
$file->saveAs(Yii::app()->basePath.'/../images/'.$model->image); | |
$this->redirect(array('index')); | |
} | |
} | |
$this->render('_form', compact('model')); | |
} | |
/** | |
* Creates a new item. | |
*/ | |
public function actionCreate2() | |
{ | |
$model = new Item(); | |
if (isset($_POST['Item'])) | |
{ | |
$model->attributes = $_POST['Item']; | |
if ($model->validate()) | |
{ | |
$file = CUploadedFile::getInstance($model, 'image'); | |
$model->image = $this->uniqId.'.'.$file->extensionName; | |
$model->save(false); | |
$file->saveAs(Yii::app()->basePath.'/../images/'.$model->image); | |
$this->redirect(array('index')); | |
} | |
} | |
$this->render('_form', compact('model')); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment