hey guys, in a n00b at Yii, and i’m trying to make 2 controllers works in this order:
make a course, add an event. so far i can create my course, save the model, and get to the event form. then it’s supposed to redirect to some other controller, but still takes me back to the past step.
here are my controllers:
CursoController:
public function actionAltaCurso() {
$model=new Curso(); //create the model
if(Yii::app()->getRequest()->getIsAjaxRequest())
{
echo CActiveForm::validate( array($model));
Yii::app()->end();
}
if(isset($_POST['Curso']))
{
// collects user input data
$model->attributes=$_POST['Curso'];
// validates user input and redirect to previous page if validated
if($model->validate()) {
$usuario = $this->getUsuarioSession();
$model->USUARIO_owner = $usuario["id"];
$model->fechacreacion = "hoy";
$model->estado = 0;
$model->save();
$comisionActual = new Comision(); //("Comision" means event)
$comisionActual->CURSO_idCURSO = $model->idCURSO;
IF I USE THIS ONE, EVERYTHING GOES OK, BUT NEXT STEP TAKES ME BACK HERE
//$this->render(’/site/curso/altaComision’, array(“curso” => $model,“comisionActual”=>$comisionActual));
IF I USE THIS, IT GIVES ME AN ERROR404 BUT RECEIVE THE idCURSO
$this->redirect(array("curso/altaComision?Comision=$model->idCURSO"),true);
return;
}
}
// displays the login form
$tematicas = Tematica::model()->findAll(array('order'=>'nombre'));
$tiposCurso = Tipo::model()->findAll(array('condition'=>"tabla='CURSO'"));
$datos = array('model'=>$model,
'tematicas'=>$tematicas,
'tiposCurso'=>$tiposCurso,
);
$this->render('/site/curso/altaCurso', $datos);
}
ComisionController:
here is the "next step"
public function actionAltaComision(){
$model = new Comision();
//$model->CURSO_idCURSO = $_POST[$model->idCURSO] ;/* $comisionActual;*/
//$cursoActual = $curso;
if(Yii::app()->getRequest()->getIsAjaxRequest())
{
echo CActiveForm::validate( array($model));
Yii::app()->end();
}
if(isset($_POST['Comision']))
{
// collects user input data
$model->attributes=$_POST['Comision'];
// validates user input and redirect to previous page if validated
if($model->validate()) {
$model->save();
//$this->redirect("index.php?r=curso/detalle&id=".$cursoActual->idCURSO,true);
//$this->redirect("index.php?r=comision/crear&idcurso=".$model->idCURSO,true);
//$this->redirect(array("/site/index"),true);
$url = Yii::app()->createUrl('projects/view')."&id=$model->projectID#uniqe_$id";
$this->redirect($url);
//$this->render('/site/curso/mensajeCreacionCurso'/*mensajeCreacionCurso*/, array("comision" => $model,"curso"=>$CursoActual));
return;
}
}
// displays the login form
$this->render('/site/curso/altaComision',array("Comision" => $model));
}
problem must be in cursoController (if i use render, loops. if i use redirect, gives me error404
please help! thx for any reply…