/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $modelUsuario = new Usuario();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($modelUsuario);
     if (isset($_POST['Usuario'])) {
         $modelUsuario->attributes = $_POST['Usuario'];
         $modelUsuario->orgao_id = 1;
         $modelUsuario->senha = md5(SALT_MD5 . $_POST['Usuario']['senha']);
         //$modelUsuario->senha = md5(SALT_MD5 . $_POST['Usuario']['senha']);
         $modelUsuario->data_cadastro = date('Y-m-d');
         $modelUsuario->avatar = CUploadedFile::getInstance($modelUsuario, 'avatar');
         if ($modelUsuario->save()) {
             // Preferência
             $modelPreferencia = new Preferencia();
         }
         $modelPreferencia->usuario_id = $modelUsuario->id;
         $modelPreferencia->save();
         $this->redirect(array('admin', 'id' => $modelUsuario->id));
     }
     $this->render('create', array('model' => $modelUsuario));
 }
Esempio n. 2
0
 public static function addInstanceToPool(Preferencia $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         self::$instances[$key] = $obj;
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($usuario)
 {
     $model = Preferencia::model()->findByAttributes(array('usuario_id' => $usuario));
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }