controllers/BannerController.php
public function actionCreate()
    {
        $model = new Banner();
        $model->time = date("Y-m-d H:i:s");
        $model->position = $model->getLast();
        $model->isdel = 0;
		
		$post = Yii::$app->request->post();
		if (isset($post['Banner']['tags']))
		{
			if (is_array($post['Banner']['tags']))
			{
				$post['Banner']['tags'] = implode(",",$post['Banner']['tags']);
			}	
		}
		
		$transaction = Yii::$app->db->beginTransaction();
		try {				
			if ($model->load($post) && $model->save()) {
				$model->updatePosition($model->position);
				$transaction->commit();
				return $this->redirect(['view', 'id' => $model->id]);
			}					
			else
			{
				$transaction->rollBack();	
			}
		} catch (Exception $e) {
			$transaction->rollBack();
		}
		
		return $this->render('create', [
			'model' => $model,
		]);
	
    }
public function actionCreate()
    {
        $model = new Banner();
        $model->time = date("Y-m-d H:i:s");
        $model->position = $model->getLast();
        $model->isdel = 0;
		
		$post = Yii::$app->request->post();
		if (isset($post['Banner']['tags']))
		{
			if (is_array($post['Banner']['tags']))
			{
				$post['Banner']['tags'] = implode(",",$post['Banner']['tags']);
			}	
		}
		
		$transaction = Yii::$app->db->beginTransaction();
		try {				
			if ($model->load($post) && $model->save()) {
				$model->updatePosition($model->position);
				$transaction->commit();
				return $this->redirect(['view', 'id' => $model->id]);
			}					
			else
			{
				$transaction->rollBack();	
			}
		} catch (Exception $e) {
			$transaction->rollBack();
		}
		
		return $this->render('create', [
			'model' => $model,
		]);
	
    }
public function actionCreate ( ) { $ model = new Banner ( ) ; $ model -> time = date ( "Y-m-d H:i:s" ) ; $ model -> position = $ model -> getLast ( ) ; $ model -> isdel = 0 ; $ post = Yii :: $ app -> request -> post ( ) ; if ( isset ( $ post [ 'Banner' ] [ 'tags' ] ) ) { if ( is_array ( $ post [ 'Banner' ] [ 'tags' ] ) ) { $ post [ 'Banner' ] [ 'tags' ] = implode ( "," , $ post [ 'Banner' ] [ 'tags' ] ) ; } } $ transaction = Yii :: $ app -> db -> beginTransaction ( ) ; try { if ( $ model -> load ( $ post ) && $ model -> save ( ) ) { $ model -> updatePosition ( $ model -> position ) ; $ transaction -> commit ( ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } else { $ transaction -> rollBack ( ) ; } } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
Creates a new Banner model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Banner model . If creation is successful the browser will be redirected to the view page .