Questions tagged [cakephp-model]

App models are the classes that sit as the business layer in a CakePHP application.

App models classes are responsible for managing almost everything that happens regarding data, its validity, interactions and evolution of the information workflow in a CakePHP project.

Usually model classes represent data and are used in CakePHP applications for data access, more specifically they represent a database table but they are not limited to this, but can be used to access anything that manipulates data such as files, external web services, iCal events, or rows in a CSV file.

Source: Manual Reference

Example: (CakePHP 2.x)

App::uses('AppModel', 'Model');
class Ingredient extends AppModel {
    public $name = 'Ingredient';
}
501 questions
3
votes
2 answers

Load model or $uses array which need to be used ? while we accessing other models

I have a users controllers, I need to use photos model on that users_controllers which can i use to access that model from the following and which is standard to use? $this->loadModel('Photo'); or var $uses =array('User','Photo'); Load model or…
AnNaMaLaI
  • 4,064
  • 11
  • 53
  • 93
3
votes
2 answers

CakePHP alternative to Class Table Inheritance?

I want to create a Class Table Inheritance model in CakePHP. I would like to have a Model called something like ProductBase with the table product_bases to hold all the base information every product should have, like upc, price, etc. Then have…
JD Isaacks
  • 56,088
  • 93
  • 276
  • 422
3
votes
2 answers

CakePHP - recursive on specific fields in model?

I'm pretty new to CakePHP but I think I'm starting to get the hang of it. I'm trying to pull related table information recursively, but I want to specify which related models to recurse on. Let me give you an example to demonstrate my goal: I have…
Paul Willy
  • 55
  • 1
  • 7
3
votes
2 answers

CakePHP model relation having 2 foreign key on the same table

I have this database design Applicant Table id | country_id | country_now_id Country Table id | name The country_id is an FK to the Country Table, and the country_now_id is also an FK of Country Table. My question is how would I write this one in…
PinoyStackOverflower
  • 5,214
  • 18
  • 63
  • 126
3
votes
4 answers

Should controllers avoid private functions at CakePHP?

I was wondering if controllers at CakePHP should not contain any private function which is not accessible by URL. Sometimes some functions such as add or delete can be so large that I prefer to divide them. Should I put that functions inside the…
Alvaro
  • 40,778
  • 30
  • 164
  • 336
3
votes
2 answers

cakephp HABTM association

Hi I have a site develop in cakephp. I have two tables: Ingredient Property The relation between the tables is HasAndBelongsToMany(HABTM). This is my model: class Ingredient extends AppModel { public $name = 'Ingredient'; public $useTable =…
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
3
votes
2 answers

A CakePHP query calls COUNT() twice for no apparent reason

Note: I originally asked this question about an hour ago but only recently realized I had made a major copy and paste mistake. One so significant that it was easier to delete the old post and start over. Sorry about that. In the CakePHP framework,…
user1449855
  • 1,195
  • 2
  • 10
  • 14
2
votes
1 answer

CakePHP 2.0 - Plugin Model without an underlying database table

I'm having difficulty in creating a Cake 2.0 plugin with a model that is not associated with an underlying database table. The Cake Manual says that you can set the variable public $useTable = false; but when I load my plugin with this in my model I…
Andy
  • 2,095
  • 1
  • 29
  • 59
2
votes
1 answer

Models with two hasOne relations to same table

I'm building an MMA (mixed martial arts) website with CakePHP. I've got a fights table in my database that has three columns at its simplest: id, fighter_a, and fighter_b. I'm having trouble getting my head around what type of relation my Fight…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
2
votes
2 answers

How to validate associated models

I've got Product and Category models in my application. A product can belong to only one category. These are shown within a drop down list in the "New Product" form. What I would like to do is that when I create a new product, the app validates the…
Leonel
  • 91
  • 1
  • 5
2
votes
3 answers

How do I avoid magic strings (PHP MVC Frameworks)

I want to use a MVC-framework together with PHP to make a nice separation between code and presentation. I've currently started to look at CakePHP. It looks nice, but whats about all those magic strings? Take a look at the code below (taken from the…
SanSaurus
  • 63
  • 4
2
votes
1 answer

when i use findby($id) with association conditions i get SQL Error: 1054

i use this variable to find the comments that related with articles.. $comment = $this->Article->Comment->findAllById($id); i get errors when i added conditons like this.. $comment = $this->Article->Comment->findAllById($id,array('conditions' =>…
user1080247
  • 1,076
  • 4
  • 21
  • 51
2
votes
3 answers

MVC Models, what are they for?

The time has come for me to understand MVC, so that's what I'm trying to do; and I'm having trouble getting what a model is supposed to do. According to Wikipedia, a model: The model manages the behaviour and data of the application domain, …
Misguided
  • 1,302
  • 1
  • 14
  • 22
2
votes
1 answer

cakePHP duplicating a function or using an outer controller? (DRY issue)

I have 3 controllers, Tokens, Stores and Users. Token is related to the two other models, for each token there is a owner-type and owner-id. There is also a function in both User_controller and Store_controller, called EmailTokenToUser which send…
yossi
  • 3,090
  • 7
  • 45
  • 65
2
votes
4 answers

Calling one model from another in CakePHP

I have one user model and other is accesscode model. During registration I am using the user model where I have set some validation rules for form data. On the registration page I have one field which does not belong to the user model i.e. the…
1 2
3
33 34