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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:20:17+00:00 2026-06-05T18:20:17+00:00

Possible Duplicate: CakePHP: Call to a member function find() on a non-object I have

  • 0

Possible Duplicate:
CakePHP: Call to a member function find() on a non-object

I have three Models: Product, Prodpage, Field.

I did the cake console to bake all models based on my local mysql db on my pc. I then created a simple controller for each model utilizing the public $scaffold. Here is the ProductsController example:

<?php
// app/Controller/ProductsController.php
class ProductsController extends AppController {
  public $scaffold;
}

went into my app (localhost/cake/products) and everything worked fine. I could add products, delete products, edit products. I could then add prodpages, and I could also add the fields. I decided to go ahead and use the cake console to bake the controllers and views. It was my understanding that it should do the same thing as the $scaffold, but this time the controllers should have more of the code in it. Thus allowing me to start to customize it a bit more.

I go back to localhost/cake/products and it was working fine. Then when I try to go to localhost/cake/prodpages/add and I get this error:

Fatal error: Call to a member function find() on a non-object in C:\wamp\www\cake\app\Controller\ProdpagesController.php on line 50

Here is the ProdpagesController all they way through line 53(the add function):

<?php
App::uses('AppController', 'Controller');
/**
 * Prodpages Controller
 *
 * @property Prodpage $Prodpage
 */
class ProdpagesController extends AppController {


/**
 * index method
 *
 * @return void
 */
    public function index() {
        $this->Prodpage->recursive = 0;
        $this->set('prodpages', $this->paginate());
    }

/**
 * view method
 *
 * @param string $id
 * @return void
 */
    public function view($id = null) {
        $this->Prodpage->id = $id;
        if (!$this->Prodpage->exists()) {
            throw new NotFoundException(__('Invalid prodpage'));
        }
        $this->set('prodpage', $this->Prodpage->read(null, $id));
    }

/**
 * add method
 *
 * @return void
 */
    public function add() {
        if ($this->request->is('post')) {
            $this->Prodpage->create();
            if ($this->Prodpage->save($this->request->data)) {
                $this->Session->setFlash(__('The prodpage has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The prodpage could not be saved. Please, try again.'));
            }
        }
        $products = $this->Prodpage->Product->find('list');
        $this->set(compact('products'));
    }

and this is line 50,

$products = $this->Prodpage->Product->find('list');

Anybody know what I am doing wrong here or elaborate on what the error is telling me? I’m new to cakephp so I am walking through tutorials. This has me stumped though.

Update: Model/Product.php

<?php
App::uses('AppModel', 'Model');
/**
 * Product Model
 *
 * @property Prodpages $Prodpages
 */
class Product extends AppModel {
/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'product_name';
/**
 * Validation rules
 *
 * @var array
 */
    public $validate = array(
        'product_name' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        's7_location' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'created' => array(
            'datetime' => array(
                'rule' => array('datetime'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'modified' => array(
            'datetime' => array(
                'rule' => array('datetime'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * hasMany associations
 *
 * @var array
 */

    public $hasMany = array(
        'Prodpages' => array(
            'className' => 'Prodpages',
            'foreignKey' => 'id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );

}

Here is Model/Prodpage.php

<?php
App::uses('AppModel', 'Model');
/**
 * Prodpage Model
 *
 * @property Products $Products
 * @property Fields $Fields
 */
class Prodpage extends AppModel {
/**
 * Display field
 *
 * @var string
 */
    public $displayField = 'page_name';


/**
 * Validation rules
 *
 * @var array
 */
    public $validate = array(
        'is_blank' => array(
            'boolean' => array(
                'rule' => array('boolean'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'page_order' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        's7_page' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'created' => array(
            'datetime' => array(
                'rule' => array('datetime'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'modified' => array(
            'datetime' => array(
                'rule' => array('datetime'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
    public $belongsTo = array(
        'Products' => array(
            'className' => 'Products',
            'foreignKey' => 'products_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

/**
 * hasMany associations
 *
 * @var array
 */
    public $hasMany = array(
        'Fields' => array(
            'className' => 'Fields',
            'foreignKey' => 'id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );

}

I did the cake console to bake these models, so I did the associations within there. I thought I had Prodpage and Product related correctly. One product can have many Prodpages. One Prodpage belongs to one product.

UPDATE W/ QUERY ERROR

So when I go to localhost/cake/prodpages/add and fill out the info, selecting a Product from the product dropdown list I get this error

Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`builder_cake`.`prodpages`, CONSTRAINT `fk_prodpages_products` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)

SQL Query: INSERT INTO `builder_cake`.`prodpages` (`page_name`, `is_blank`, `page_order`, `s7_page`, `modified`, `created`) VALUES ('Page 2', '0', 2, 2, '2012-06-13 16:51:35', '2012-06-13 16:51:35')

I looked into to it and it is not passing the product_id associated with the dropdown list selection to add into into the product_id column in my Prodpages table.. any thoughts why?

  • 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-05T18:20:19+00:00Added an answer on June 5, 2026 at 6:20 pm

    It looks like your model names are plural, when they should be singular. For example:

    public $belongsTo = array(
        // Product, not Products
        'Product' => array(
            'className' => 'Product',
            'foreignKey' => 'products_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call to a member function on a non-object I try to call
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: What is the difference between save and saveAll function in cakephp? 66
Possible Duplicate: What is the most efficient way to clone a JavaScript object? (Most
Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: What is the difference between a function expression vs declaration in JavaScript?
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: What are the stages of compilation of a C++ program? I find

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.