Exemplo n.º 1
0
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
        if(Yii::app()->user->checkAccess('admin')){
            $model=new Fuels;

            if(isset($_POST['Fuels']))
            {
                $model->attributes=$_POST['Fuels'];
                $fuelCost = new FuelCost;
                $fuelCost->cost = $_POST['Fuels']['cost'];
                if ($model->validate() && $fuelCost->validate()) {
                    if($model->save(false)) {
                        $fuelCost->fuel_id = $model->id;
                        if ($fuelCost->save(false))
                            $this->redirect(array('view','id'=>$model->id));
                    }
                }
            }

            $this->render('create',array(
                'model'=>$model,
            ));
        } else {
            $this->redirect('/admin/user/login');
        }
	}
Exemplo n.º 2
0
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new FuelCost;

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

		if(isset($_POST['FuelCost']))
		{
			$model->attributes=$_POST['FuelCost'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}