Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthoralake

    Will someone please discuss the usage and implications of redirectTo, renderActionand 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?

    • CommentAuthorfixxxer

    In the documentation for the redirectTo() function (AkActionController.php), it says that the "redirection happens as a '302 Moved' header". So, I suppose that when you're using this function, you're moving to another page just like a meta refresh call and that's probably why the flash message appears. I think that flash messages are always shown on the next page you visit (but I may be wrong).

    The renderAction() uses the render() function, it's a kind of shortcut. It just change what will be shown to the user.

    I suppose that in your case, you could probably split your code to have a validation action that will be used when your "Save" button is pressed. This action will validate and redirect to the right place it needs to be.

    Hope it helps
    • CommentAuthorKaste

    If the validation succeeded, I used [...]

    then most of the time you redirectTo(action=>home)

    Did you see $this->flash_now?

    • CommentAuthoralake

    My controller code contained

    $this->flash['error'] = 'Error message';

    My view code contained

    <%= flash %>

    This worked.

    • CommentAuthoralake

    The flash notes in this post have been added to the Wiki at Flash - Communicating Between Actions