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 5989307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:04:58+00:00 2026-05-22T23:04:58+00:00

I am new to cakephp. I am trying to put a query in after

  • 0

I am new to cakephp. I am trying to put a query in after getting the result part in model and use it in call back. But getting errors when I try to get the debug of $newArray from model.. In my controller I have this

function index($var = null){


             if (empty($this->data)) {




             } 
             else { 


                            $results = array();

                            $getRecords = $this->Model->find('all');
                                $results = $this->Model->afterFind($getRecords);
                                debug($this->newArray);

            }
    }

In my Model I have this

class Model extends AppModel {
function afterFind($getRecords){
    $newArray = array();    
    $query_string = $getRecords['Record']['column1']" ;
    $results = $this->Model->query($query_string);
        foreach($results as $result){


        //do something and add to $newArray

        }
        return $newArray;

    }
}
  • 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-22T23:04:59+00:00Added an answer on May 22, 2026 at 11:04 pm

    Callbacks are automatically called by Cake, you do not call them by hand (that’s the point, otherwise they’d be normal methods). The flow is:

    • Controller calls Model::find
    • Cake triggers Model::beforeFind callback, if present
    • Cake finds results
    • Cake triggers Model::afterFind callback if present, passing in an array of found data
      • the callback is supposed to return data
    • Controller receives the data returned by Model::afterFind

    There are examples for afterFind in the manual. You should not trigger further queries from afterFind, as this may go into an infinite loop, with each query triggering more afterFind callbacks. I also wouldn’t suggest to alter your results too drastically in an afterFind, you should only do light massaging of the results where necessary. I can’t tell from your post what it is you’re trying to achieve, so I can’t give any concrete hints, but you can probably do it without afterFind by formulating a better query in the controller.

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

Sidebar

Related Questions

I'm trying to use Ajax in CakePHP, and not really getting anywhere! I have
So I'm trying to implement the evercookie on a cakePHP website, but I'm getting
I'm new to cakephp and trying to write a simple app with it, however
I am new to cakephp and I'm trying to accomplish something that should be
I'm new to CakePHP but I've been though their FAQs and guides to no
I'm new to CakePHP and am just running through the configuration process, but am
I'm pretty new to CakePHP but I think I'm starting to get the hang
I am using cakephp. I am trying to use httpsocket to get information. <?php
I'm new to the MVC pattern but have been trying to grasp it, for
I'm new to CakePHP, and I'm trying to decide between the schema shell that

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.