<?php
/**
 * Descriptions
 * @author yzxh24
 * @email yzxh24@gmail.com
 * @created 2010-05-14 15:07:00
 */
class CreateAction extends BaseAction
{
    public function run()
    {
        $model = new Label();
		if (isset($_POST['Label']))
		{
			$model->attributes = $_POST['Label'];
			$model->validate();
			$errors = $model->getErrors();
			if (empty($errors))
			{
				$model->save();
				if (Yii::app()->getRequest()->getIsAjaxRequest())
				{
					exit();
				}
				else
				{
					$this->getController()->redirect(array('list'));
				}
			}
			else
			{
				if (Yii::app()->getRequest()->getIsAjaxRequest())
				{
					foreach ($errors as $error)
					{
						foreach ($error as $value)
						{
							$message[] = $value;
						}
					}
					echo implode("\n", $message);
                    Yii::app()->end();
				}
			}
		}
        
		$this->getController()->render('create', array('model' => $model));
    }
}