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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:06:03+00:00 2026-05-31T00:06:03+00:00

When I post to this controller, I get this back as the response: Fatal

  • 0

When I post to this controller, I get this back as the response: Fatal error: Call to a member function find() on a non-object in /app/Controller/AppController.php on line 26 which probably has to do with using $this->data() explicitly. I was using CakePHP save without form
per a recommendation in there, but since I’m not using a form to send the data (thus not using $this->request->data()), I’d like to know what the replacement is for $this->data() so I can get this working.

My database table is is submissions_favorites.

This is my SubmissionFavorite model:

class SubmissionFavorite extends AppModel {

    var $name = 'SubmissionFavorite';

    var $belongsTo = array(
        'User' => array(
            'className' => 'User'
        )
    );

}

This is AjaxController (what I’m posting to):

class AjaxController extends AppController {

    var $layout = 'ajax';  // uses an empty layout
    var $autoRender = false; // renders nothing by default
    var $uses = 'SubmissionFavorite';

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->loginRedirect = array('controller' => 'home', 'action' => 'index');
        $this->Auth->allow('addFavorite');
        $this->Auth->flashElement = 'flash_error';
    }

public function addFavorite() {
    $this->autoRender = false;

    $this->data['SubmissionFavorite']['user_id'] = $this->Session->read('Auth.User.id');
    $this->data['SubmissionFavorite']['submission_id'] = $_POST['id'];
    $this->data['SubmissionFavorite']['when'] = DboSource::expression('NOW()');

    $message = array('success' => 'success');

    $toReturn = json_encode($message);

    if ($this->RequestHandler->isAjax()) {
        if ($this->Session->read('Auth.User')) {
            $this->SubmissionFavorite->save($this->data);
            return $toReturn;
        } else {
            $login = array('login' => 'Please log in to add favorites');
            return json_encode($login);
        }
    }
}

Line 26 in my AppController is:

protected function getSubmissionCount() {
    $totalSubmissions = $this->Submission->find('count');
    return $totalSubmissions;
}

Which is totally unrelated to anything else. I didn’t even add anything to AppController when I wrote the new method within my AjaxController, so I’m not sure how it’s relevant (or why I’m even getting an error in that file).

  • 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-31T00:06:04+00:00Added an answer on May 31, 2026 at 12:06 am

    First, following cake conventions, you should name your model SubmissionsFavorite (note the s between Submission and Favorite). This is because your table name is composed by 2 words, even representing a relationship between 2 other tables.

    Also, you can’t do $this->Submission->… on AppController without telling cake whatever is “Submission”. Take a look at this link to see how to initialize Submission model and use it on AppController: Can I use one model inside of a different model in CakePHP?

    Regards.

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

Sidebar

Related Questions

With this controller method: - [AcceptVerbs(HttpVerbs.Post)] public ViewResult Contact(Contact contactMessage) { return View(); }
How can in controller redirect with post same data like this do form <form
This is working, but how??? I have a controller action for a post: [AcceptVerbs(HttpVerbs.Post
I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I have this function from a plugin (from a previous post) // This method
i have this problem to find a particular xml node l have post this
I am using a gem which uses soap/wsdlDriver. When I post I get back
I am trying to POST data back to the server and get a dataset
this is from my controller.. @RequestMapping(value = /add, method = RequestMethod.GET) public String add(Model
I post this previously in Adobe Forum but haven't got any answers so far.

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.