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

  • SEARCH
  • Home
  • 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 7057293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:58:07+00:00 2026-05-28T03:58:07+00:00

After adding this to the end of my display function inside app/controllers/pages_controller.php , //

  • 0

After adding this to the end of my display function inside app/controllers/pages_controller.php,

    // grab all message lists
    $this->loadModel('MessageList');
    $this->set('messageLists', $this->MessageList->find('all'));

I try to access it in app/views/pages/home.ctp like

<?php
        foreach($messageLists as $messageList) {
            print_r($messageList);
        }
    ?>

But I get the warning

Notice (8): Undefined variable: messageLists [APP\views\pages\home.ctp, line 9]

My app/config/routes.php has:

/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/views/pages/home.ctp)...
 */
    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's urls.
 */
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

What do I need to change so that I can access $messageLists in my home page? Thanks!

  • 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-05-28T03:58:07+00:00Added an answer on May 28, 2026 at 3:58 am

    At the very end of your display() method? Well this won’t work because its calling render() before and by this render the page before you set the view vars for it. So move your set() call before the render() call.

    Also a further hint: Your implementation is not very well done except you want to cause additional queries on each page that does not even need to display the messages.

    It looks like you’re a CakePHP beginner so I suggest you to lookup requestAction() in the manual and how elements in the views work. This would allow you to display the list of messages using an element in any view file by using an element and a request action to for example Messages/getListForUser.

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

Sidebar

Related Questions

I'm having a memory problem related to UIImageView. After adding this view to my
I am getting this error after adding the libxml2.2.dylib file Linking /Users/Biranchi/Desktop/Funmovies TabBarController/build/Debug-iphonesimulator/funmovies.app/funmovies (1
When adding this code to a simple calculator program I receive the error message
I'm receiving NoMethodError in Users#new after adding the partial app/views/shared/_error_messages.html.erb Showing /Users/gjb/Sites/rails_projects/sample_app/app/views/shared/_error_messages.html.erb where line
I'm working to install the acts_as_commentable plugin on my Rails 3 app. After adding
After adding the /TSAWARE linker flag to one of my projects (Visual Studio 6),
After adding the key value pairs in NSMutableDictionary, when i retrive the key/values from
I'm using aspxgridview and after adding operation by using RowInserting event and I don't
Does anyone know what the esiest way to update the entity model after adding/deleting
I'm using set_cookie() on a site. After adding some functionality, I'm getting Warning: Cannot

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.