/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PessoaCategoria(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['PessoaCategoria'])) { $model->attributes = $_POST['PessoaCategoria']; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
/** * * Coloca as categorias do modelo * @param Pessoa $model */ protected function saveCategory($model) { //Salva as categorias que esta pessoa possui. PessoaCategoria::model()->deleteAll('cod_pessoa = ' . $model->cod_pessoa); for ($i = 0; $i < count($model->categorias); $i++) { $categoria = new PessoaCategoria(); $categoria->cod_categoria = $model->categorias[$i]; $categoria->cod_pessoa = $model->cod_pessoa; $categoria->save(); unset($categoria); } }