Okay, can someone tell me where the render for the second view goes in the following example (and why)? I just want to do a simple branching based on a value entered; according to the log, everything is good, but I don’t see the redirect rendered as expected…
Any corrections to my thinking appreciated!
Controller:
public function actionFirst() {
$this->render('first');
Yii::trace('Info returned: ['.print_r($_POST,true).']', 'info');
if (isset($_POST['val']) && ($_POST['val'] === 'ABC')) {
Yii::trace('Match...', 'info');
$this->redirect(array('test/second'));
} else {
Yii::trace('No match...', 'info');
}
}
public function actionSecond() {
$this->render('second');
}
You should probably try this out and see if it redirects correctly:
public function actionFirst() {
$this->redirect(array('test/second'));
}
If this doesn’t work, it might be that you’re accidentally sending some whitespace out before you get to the redirect line. You could check the output for leading whitespace before the html generated by your controller.
To avoid leading whitespace, make sure all the pure php files you code start with <?php and contain no end tag.
Yeah, that redirect works fine. In fact, for the regular case, I’m able to see that the render takes in all the info correctly and constructs good output, then calls echo. The only thing that doesn’t occur is the actual page update in the browser.
Sorry, this feels like a total newbie problem, but I’m at a loss…
Yeah, I think I missed the important issue. Hopefully this will be more helpful:
If I’m reading your original code right, you’re calling this controller with an ajax call, so the redirect will get processed within the ajax call. So your server is returning the data from actionSecond, but the ajax is just throwing this data away.
You need to add either a ‘replace’, ‘update’, or ‘success’ option to your ajax call in order to do something with this output.
Alternatively, move away from ajax and rewrite this as a form that simply submits an http post request. If you are planning on doing some server side processing and then redirecting the browser to another page there is no need to use ajax.
My intent was to capture some pieces of info via a CJuiDialog widget, then look at that info on the server side, process things accordingly, and redirect the user to an appropriate page. Not sure how I managed to mangle things up, but I think you’re right about ajax tossing out my page. After reading through the links you provided, I’m inclined to re-think my approach and move away from ajax, as you suggest, but I’ll tinker with it a bit to see if I can’t get a reasonable mechanism to work with the dialog thingy…