<?php
/**
 * Descriptions
 * @author yzxh24
 * @email yzxh24@gmail.com
 * @created 2010-06-28 19:11:33
 */
class UpdateAction extends BaseAction
{
    public function run()
    {
        //put your code here
        $model = Books::model()->findByPk($_GET['id']);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Books']))
		{
			$model->attributes = $_POST['Books'];
            $image = CUploadedFile::getInstance($model, 'image');
            if (is_object($image) && get_class($image) === 'CUploadedFile')
            {
                $model->imageObj = $image;
            }

			if($model->save())
            {
				$this->getController()->redirect(array('list'));
            }
		}

        $types = Type::model()->findAll("type='book'");

		$this->getController()->render('update',array(
			'model' => $model,
            'types' => $types,
		));
    }
}