Hi,
I’ve a problem with rendering back to the url specified and I can’t seem to find any ways to solve it.
I’m new to yii framework and I’m not sure what I’m doing is correct.
Basically, what I’m trying to do is when I click on a link at a page, a pop-up form will appear so that I can fill in accordingly. When I click on the submit button on the form, it will go to the controller which will then communicate with the respective modal to save the info filled in by the user in the pop-up form to the database. Thereafter, the pop-up form will close and it will direct the user back to page with the link.
My directory structure:
[b]Project Module
View[/b]
- index.php
- ProjectDialog.php
[b]Controller
Default[/b]
- DefaultController.php
Modal
- Project.php
In index.php, it has a link and when clicked, it calls a cjuidialog which renders a form from ProjectDialog.php:
<?php
echo CHtml::link('Create Project', '#', array(
'onclick'=>'$("#mydialog").dialog("open"); return true;',
));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'mydialog',
'options'=>array(
'title'=>'Project',
'autoOpen'=>false,
'width'=>'auto',
),
));
echo $this->renderPartial('ProjectDialog', array('modelProject'=>$modelProject, 'list'=>$list));
?>
ProjectDialog.php is a cactiveform:
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'project-form',
'enableAjaxValidation'=>false,
'enableClientValidation' => true,
'clientOptions' => array('validateOnSubmit'=>true),
'action'=>array('Default/SubmitProject'), //call DefaultController.php, actionSubmitProject method
));
?>
DefaultController.php processes the cactiveform of ProjectDialog.php. It should render back to project module’s index.php view (view’s url only - index.php?r=project:
public function actionSubmitProject()
{
... //logic to communicate with modal
$this->render('index', array('modelProject'=>$modelProject, 'list'=>$list,)); //should direct back to index.php?r=project but it keeps going to index.php?r=project/Default/SubmitProject
}
For the DefaultController.php, it should render back to project module’s index.php view (i.e. url should be view’s url only - index.php?r=project) but the url keeps displaying the view with controller action url(i.e. index.php?r=project/Default/SubmitProject).
The page displayed is the page that I want (index.php) but the url is not the correct url (it shows index.php?r=project/Default/SubmitProject instead of index.php?r=project).
I want the url to be view’s url only (index.php?r=project) because if it is at the view controller action url(index.php?r=project/Default/SubmitProject), and I refresh the page, it will keep running the into the controller action which creates multiple entries into the database.
Is there any way to solve the problem? Or is the method that I’m currently doing wrong?
Thanks!