/** * Crea un Controlador para el menu * */ public function create() { //Datos del select $this->perfiles = $this->Perfiles->find('order: nombre'); $this->menus = $this->Menus->find('order: nombre'); /** * Se verifica si el usuario envio el form (submit) y si ademas * dentro del array POST existe uno llamado "controllers" * el cual aplica la autocarga de objeto para guardar los * datos enviado por POST utilizando autocarga de objeto */ if ($this->has_post('controllers')) { /** * se le pasa al modelo por constructor los datos del form y ActiveRecord recoge esos datos * y los asocia al campo correspondiente siempre y cuando se utilice la convención * model.campo */ $controller = new Controllers($this->post('controllers')); //En caso que falle la operación if (!$controller->save()) { Flash::error('Falló Operación'); //se hacen persistente los datos en el formulario $this->controllers = $this->post('controllers'); /** * NOTA: para que la autocarga aplique de forma correcta, es necesario que llame a la variable de instancia * igual como esta el model de la vista, en este caso el model es "controllers" */ } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Controllers('create'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Controllers'])) { //Check controller name, action name - PDQuang if ($_POST['Controllers']['module_name'] == null) { $checkController = ControllerActionsName::checkControllerActionsExist($_POST['Controllers']['controller_name'], $_POST['Controllers']['actions']); } else { $checkController = ControllerActionsName::checkControllerActionsExist($_POST['Controllers']['controller_name'], $_POST['Controllers']['actions'], $_POST['Controllers']['module_name']); } if (!$checkController) { Yii::log('Controller, Module or Actions is wrong!'); throw new CHttpException('Controller, Module or Actions is wrong!'); } $model->attributes = $_POST['Controllers']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'actions' => $this->listActionsCanAccess)); }