Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:53:09+00:00 2026-06-02T22:53:09+00:00

So in blog cakephp 2.0 tutorial, there are following lines http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html <?php public function

  • 0

So in blog cakephp 2.0 tutorial, there are following lines
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html

<?php
public function edit($id = null) {
    $this->Post->id = $id;
    if ($this->request->is('get')) {
        $this->request->data = $this->Post->read();
    } else {
        if ($this->Post->save($this->request->data)) {
            $this->Session->setFlash('Your post has been updated.');
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash('Unable to update your post.');
        }
    }
}

Why does $this->Session->setFlash(‘Your post has been updated.’); go before the redirect line? Once it gets redirected, why does the message get displayed and not let’s say vice versa. First redirect and then flash the message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:53:10+00:00Added an answer on June 2, 2026 at 10:53 pm

    The method will issue an exit() after the redirect unless you set the third parameter to false.

    In this case, setFlash adds your message to the session, which can then be displayed in your view when the page you redirect to loads. By default redirect calls exit, so anything you put after it will never get executed. Even if you set the third parameter to false, the behaviour of setFlash would not change.

    You would use this when you wanted the message to just be a small part of the page, like the ‘this post has been edited’ or ‘a new answer has been posted’ messages you get here on SO.

    If you wanted to show the flash message before redirecting (ie. redirecting in HTML), you can use the flash method on the controller instead (note that the message would have a full page of its own):

    Like redirect(), the flash() method is used to direct a user to a new page after an operation. The flash() method is different in that it shows a message before passing the user on to another URL.

    The first parameter should hold the message to be displayed, and the second parameter is a CakePHP-relative URL. CakePHP will display the $message for $pause seconds before forwarding the user on.

    If there’s a particular template you’d like your flashed message to use, you may specify the name of that layout in the $layout parameter.

    A page showing your message will first be displayed, then it will automatically redirect a number of seconds afterwards. You can optionally pass a layout in as the fourth parameter, to have more control over its appearance.

    $this->flash('Your post has been updated.', array('action' => 'index'), 5);
    

    http://book.cakephp.org/2.0/en/controllers.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We started following the CakePHP Blog tutorial hosted on the website cakephp.org - http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
I used this tutorial: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html To build my first form/create user app, but it
I followed the tutorial for setting up simple authentication (http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html) and I am having
In CakePHP blog tutorial, http://book.cakephp.org/view/1536/Creating-Post-Views there is a code for index.ctp Html->link($post['Post']['title'], array('controller' =>
I am trying to set up a cakePHP blog. Following the steps at: http://www.marcofolio.net/webdesign/building_a_blog_with_cakephp_part_1_getting_started.html
Following the intro cakephp tutorial to create a blog, I created a database to
http://blog.helpcurenow.org/test/mockups/mar2010/lp.html In the above landing page, I have an offers box that has four
I'm following the blog tutorial on CakePHP website, but validation doesn't work and I
recently found an article in http://hashtwo.com/blog/integrating-a-file-browser-into-ckeditor-cakephp to integrate a file browser into ckeditor (file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.