public function actionAjax() { if (isset($_POST['categoria'])) { $categoria = $_POST['categoria']; $tc = new TipoCategorias(); echo json_encode($tc->getTipoCategoriasByCategoria($categoria)); } if (isset($_POST['dameusu'])) { $damecat = $_POST['dameusu']; if ($damecat) { $tc = new Usuario(); echo json_encode($tc->getUsuarios()); } } if (isset($_POST['damecat'])) { $damecat = $_POST['damecat']; if ($damecat) { $tc = new CategoriasObjetos(); echo json_encode($tc->getCategorias()); } } if (isset($_POST['dameubi'])) { $damecat = $_POST['dameubi']; if ($damecat) { $tc = new Ubicaciones(); echo json_encode($tc->getUbicaciones()); } } if (isset($_POST['damesubc'])) { $damecat = $_POST['damesubc']; if ($damecat) { $tc = new TipoCategorias(); echo json_encode($tc->getAllTipoCategorias()); } } if (isset($_POST['damecg'])) { $damecat = $_POST['damecg']; if ($damecat) { $tc = new Cuenta(); echo json_encode($tc->getConceptosGastos()); } } if (isset($_POST['dameci'])) { $damecat = $_POST['dameci']; if ($damecat) { $tc = new Cuenta(); echo json_encode($tc->getConceptoIngresos()); } } if (isset($_POST['duplicar'])) { //Llama al procedimiento $dup = $_POST['duplicar']; if ($dup) { if (isset($_POST['id']) && isset($_POST['cantidad'])) { $id = $_POST['id']; $cantidad = $_POST['cantidad']; $model = new Objeto(); try { $numRowsAffected = $model::getDb()->createCommand("call duplicarObjeto(" . $id . "," . $cantidad . ");")->execute(); $objeto = Objeto::findOne($id); echo "Se han añadido " . $cantidad . " registros más del objeto " . $objeto->tipo . " de " . $objeto->ubicacion; } catch (yii\db\Exception $e) { echo "No se ha podido duplicar según su solicitud"; } } } } }
/** * Finds the Objeto model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Objeto the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Objeto::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }