Will someone please discuss the usage and implications of redirectTo, renderAction
and similar functions?
In a controller, I have a function login(), which, of course leads to a login.tpl view. When the "Save" button is pressed, the form cycles back to the login() function, where the contents of $this->params is validated.
If the validation succeeded, I used $this->renderAction('home')
to exit the loop. If the validation fails, I make an assignment to $this->flash['error']
and the execution loops. (The view does contain <%= flash %> The logic works, but flash was not displayed in the view until after an attempt with different data was entered.
The problem was fixed when, instead of allowing the logic to fall through from the action to the view when authentication failed, I used $this->redirectTo(array('action' => 'login'))
to set up the loop.
Both redirectTo and renderAction appear to change the execution flow, but in different ways. How should a programmer determine when to use each one? Are there other similar functions that one should know about?
If the validation succeeded, I used [...]
then most of the time you redirectTo(action=>home)
Did you see $this->flash_now?
My controller code contained
$this->flash['error'] = 'Error message';
My view code contained
<%= flash %>
This worked.
The flash notes in this post have been added to the Wiki at Flash - Communicating Between Actions
1 to 5 of 5