Implement tables with error underscores: Fatal error: Call to a member function find () on boolean

when I implement a table with the name example_a. call:

  • model / entity: ExampleA.php
  • model / table: ExampleATable.php
  • controller: ExampleAController.php
  • Template / ExampleA: index.ctp

gives me the following error:
Notice (1024): Undefined property: ExampleAController :: $ ExampleA in C: Program Files …

Fatal error: Call to a member function find () on boolean

to print the list of objects in the controller implement a function:

     public function index ()
     {
         $This-> set('examples', $this-> ExampleA-> find ('all'));
     }

I specify that this table has no relationship whatsoever with other tables

if instead I do the same thing implementing a table without underscore it works

maybe your table name should have s at end (and other derivatives)? Or place full Model file here.

1 Like

I didn’t respect the conventions of cakePHP so it gave me that problem. I have revised modifying as follows:

  • names of the tables in the plural and written all lowercase
  • names model / entity in the singular with first capital letter
  • model / table plural name with first capital letter and so on for the other files

It’s certainly possible to write fully functional code that doesn’t follow the naming conventions. It’s just much easier when you do follow them.

And for creating model files cake bake model cli command is convenient (assuming that your SQL is well defined)
Personally I bake everything and then delete or change what I need.

I know I realized it

I didn’t understand this very well, but how does it work? you could give an example