PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Model name when table name has underscore

 February 17, 2022     cakephp, php     No comments   

Issue

I have a table activity_logs What should I give the model name and model file name?

I have created the model file as activityLog.php and model class name as ActivityLog

But I couldn't retrieve the data.


Solution

In cake php table names are plural and model names are singular. Table names with underscore are converted into camel case for naming models.

For example user_levels table will have model named as UserLevel:

UserLevel => user_levels

Even if you didn't create a model, Cake will let you use it and make one up on the fly for you, if you follow table names by above naming conventions.

If Cake "ignores" your model, it means it's making up another model on the fly, because you're not using the right name for the model you actually want

Looking at the generated SQL queries in debug = 2 helps



Answered By - Rajinder Deol
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing