/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Produto(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Produto']) && isset($_POST['ProdutoControle'])) { $model->attributes = $_POST['Produto']; if ($model->save()) { // Adicionando categorias if (isset($_POST['CategoriaProduto'])) { $categorias = explode(",", $_POST['CategoriaProduto']); foreach ($categorias as $key => $categoria_id) { $CategoriaProduto = new CategoriaProduto(); $CategoriaProduto->attributes = array('categoria_id' => $categoria_id, 'produto_id' => $model->id); $CategoriaProduto->save(); } } /////// Adicionando quantidade // Salvando o Controle $Controle = new Controle(); $Controle->attributes = array("funcionario_nif" => $_POST['Controle']['funcionario_nif']); $Controle->save(); // Adicionando o Produto Controle $ProdutoControle = new ProdutoControle(); $ProdutoControle->attributes = array("produto_id" => $model->id, "controle_id" => $Controle->id, "quantidade" => $_POST['ProdutoControle']['quantidade']); $ProdutoControle->save(); Yii::app()->user->setFlash('success', "Produto cadastrado com sucesso! :) "); $model->attributes = array(); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Controle(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Controle'])) { $model->attributes = $_POST['Controle']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }