Skip to content

Instantly share code, notes, and snippets.

@jamband
Created November 9, 2012 14:47
Show Gist options
  • Save jamband/4046096 to your computer and use it in GitHub Desktop.
Save jamband/4046096 to your computer and use it in GitHub Desktop.
<?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