0

I have two actions for image albums in my controller, the first creates a form to create a new album and handles the POST and the second generates a list of the existing albums. The form posts to the first action and then puts the list action on the actionstack. This order is necessary as otherwise a newly created album wouldn't appear in the list.

So in my HTML output there is first the output of the createAction-view and then of the listAction-view. But for styling reasons I want to change the order of view output of the two actions in my HTML. Is there a way I can have the list followed by the form without changing the order in which the actions are executed?

Andreas S
  • 451
  • 5
  • 17

1 Answers1

0

You should try and avoid using the action stack if at all possible. You can avoid this requirement completely by simply redirecting to the list view after handling the POST data. This also prevents users accidentally submitting the same album again by refreshing the page. If you still want the form to be displayed under the list, just add the form to that action as well so you can output it in the view under your albumn list.

public function createAction()
{
    $form = new Yourapp_Form_Album();
    if ($this->getRequest()->isPost()) {
        if ($form->isValid($this->getRequest()->getPost()) {
            // save the data and redirect
        }
    }

    $this->view->form = $form;
}

public function listAction()
{
    // load albums and assign to the view

    // if you want the form under the list
    $this->view->form = new Yourapp_Form_Album();
}
Tim Fountain
  • 33,093
  • 5
  • 41
  • 69