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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:53:55+00:00 2026-06-14T03:53:55+00:00

I keep getting a Call to a member function on a non-object error in

  • 0

I keep getting a “Call to a member function on a non-object” error in the index function of one of my controllers. Here is the code:

class ModulesController extends AppController {
     public $uses = array('Module', 'User');
     public $scaffold;
     function index() {
     if ($this->request->is('get')) { //Technically unecessary but good practice
       $email = AuthComponent::user('email'); 
       $user = $this->Module->User->findByEmail($email);
      //Code omitted
     }
}

And this is my Module model:

class Module extends AppModel {
public $name = 'Module';
public $hasMany = array(
    'Slide' => array(
        'className'  => 'Slide',
        'foreignKey' => 'module_id',
        'order' => 'Slide.position ASC' //Let's make sure that name is correct
        ));
public $belongsTo = array(
    'Creator' => array(
        'className' => 'User'));    
public $hasAndBelongsToMany = array(
    'OUser' => array(
       'className'              => 'User',
       'joinTable'              => 'modules_users',
       'foreignKey'             => 'module_id',
       'associationForeignKey'  => 'user_id',
       'unique'                 => 'keepExisting',
    ));
       } //Unnecessary code omitted 

And this is the code for my user model:

class User extends AppModel {
public $name = 'User';
public $uses = 'users';
public $hasMany = array(
    'OModule' => array( //Owner of Modules
        'className' => 'Module',
        'foreignKey' => 'user_id',
        'order' => 'Module.created DESC'
        ));
public $hasAndBelongsToMany = array(
    'Module' => array(
       'className'              => 'Module',
               'joinTable'              => 'modules_users',
               'foreignKey'             => 'user_id',
               'associationForeignKey'  => 'module_id',
               'unique'                 => 'keepExisting',
    ));
} //Unnecessary code omitted    

It is worth mentioning that User and Module have both a belongsTo and a HABTM relationship, so User has the aliases Creator and OUser respectively. In the code above, the findByEmail is trying to use the Creator relationship, but that gives me the same error.

My question is, how do I call the findByEmail() method without error?

  • 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-14T03:53:56+00:00Added an answer on June 14, 2026 at 3:53 am

    Change:

    $user = $this->Module->User->findByEmail($email);
    

    To:

    $user = $this->User->findByEmail($email);
    

    Voila!

    Reason:

    Somehow, there is either 1) no relationship between Module and User, 2) a mistake in the relationship, or 3) your using an alias for either or both of them so that using Module->User wouldn’t be correct.

    You’re loading the ‘User’ model anyway though, so there’s no reason to go through the Module model to access it – just access it directly (like example above).

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

Sidebar

Related Questions

I keep getting Fatal error: Call to a member function prepare() on a non-object
I keep getting an error Call to a member function execute() on a non-object
I keep getting this error: cannot call member function 'QString Load::loadRoundsPlayed()'without object Now im
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I am keep getting an error on my Code. I am trying to call
I keep getting this whenever I run the below code: Fatal error: Call to
At the line temp.insert(it); I keep getting the error No matching member function for
I'm trying to call mozRequestAnimationFrame in firefox, but I keep getting an error. Here
I keep getting this error when I try to call Find() public void findTxt(string
when I call my awk script, I keep getting an error : sam@sam-laptop:~/shell/td4$ awk

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.