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
0
votes
1 answer

CakePHP 2.x Saving user id from user model into events user_id field in events model from a logged in user

Hi all I am using Cakephp 2.x. I have an Events model(table) and a users model. When an event is saved I need to save the current logged in users id into the event model's user_id field. The code I have tried has been commented. Any ideas? Thanks in…
Joshua
  • 371
  • 2
  • 6
  • 23
0
votes
1 answer

Email validation error message - CakePHP

My User model: class User extends AppModel { public $validate = array( 'username' => 'alphaNumeric', 'password' => 'notempty', 'confirmpassword' => 'notempty', 'group_id' => 'notempty', 'email' => array( …
cawecoy
  • 2,359
  • 4
  • 27
  • 36
0
votes
1 answer

CakePHP 2.0 Accessing model field values for view/controller comparisons - Only letting users edit/delete their own posted items

I am fairly new to CakePHP, I am trying to only allow those users who created an event to be able to edit or delete an event, so I am comparing the current user id, with the 'user_id' field of the event the current event (saved when a user creates…
Joshua
  • 371
  • 2
  • 6
  • 23
0
votes
2 answers

CakePHP Pagination. Keeping Model Fat

I currently have this in my Model (Referer Model): public function getReferers($type = 'today') { if ($type == 'this_month') { return $this->_getThisMonthsReferers(); } elseif ($type == 'today') { return…
Teej
  • 12,764
  • 9
  • 72
  • 93
0
votes
2 answers

List posts by category in CakePHP

I'm new to CakePHP. Please help me to write a function to retrieve posts under a particular category for my blog app built using CakePHP. My table structure: posts: id, post, body, created, category_id category: id, group Also I had defined: Inside…
stacked
  • 13
  • 5
0
votes
1 answer

cakephp read and display from more than one related table

I have 2 tables Users and Artists. User: id name password city_id state_id country_id Artist: id user_id description I wish to create add and edit form(single form acts as add and edit). But on click of edit link, I wish to fill in the form…
z22
  • 10,013
  • 17
  • 70
  • 126
0
votes
1 answer

CakePHP (1.3) HABTM on the same model saveAll() not working

This seems so simple but im banging my head against the wall. I have a simple HABTM relationship (Artists hasMany Artists) and im trying to save some data. I have two tables: artists: (id, name, created, modified) artists_related: (id, artist_id,…
0
votes
2 answers

Deep association findAll() with CakePHP 2 models

I have models Trip, Investment, and Person. A single trip hasMany investments, and every investment belongsTo one Person. When I say $this->Trip->find('all'); I get: Array ( [0] => Array ( [Trip] => Array ( …
backus
  • 4,076
  • 5
  • 28
  • 30
0
votes
1 answer

Update parent model from child (belongsto) model

I have Posts and Comments and users can "Like" either. I'm using cakePHP. The Posts and Comments tables each have a 'likes' row on them because I don't want to re-count the likes each time the post / comments are loaded. I have a Likes table too,…
Tim
  • 6,986
  • 8
  • 38
  • 57
0
votes
2 answers

cakephp make same query recursive

I have a site develop in cakephp 2.0. I have a table "Product" related to property with hasMany, and HABTM to Product. A product can contain many product and that product can contain many product. I can have multiple level of product. To make this…
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0
votes
0 answers

cakephp v2.2 custom validation method isn't being called

I'm trying to use a custom validation method in cakephp 2.2.2 but for some reason the function isn't being called. Custom validation methods worked on the same system when I used cakephp for another project. I found a question on stack overflow…
nevernew
  • 650
  • 10
  • 23
0
votes
0 answers

Using Model->find('all') returns an array with the following structure

I moved a website (cakephp 2.1) from a test server ( PHP verson 5.3.10 ) to the live server (PHP verson 5.3.17). In the new situate all my code started to complaine about undefined indexes. When debugging an array I see that the array indexes…
Cake PHP
  • 163
  • 5
  • 12
0
votes
2 answers

Pass findBy parameter to callback method afterFind

I am trying to catch a certain findBy call (with afterFind) where: if $results is empty (or the value you are trying to find is nonexistent), but the parameter value is found on another table, then it will modify $results to be valid Some controller…
yowmamasita
  • 4,810
  • 3
  • 17
  • 17
0
votes
1 answer

retrieving the 'belongsTo' part of model data in cakephp

Maybe it is because I am dead tired but I am completely missing something here. I inherited a cake 1.3 app from a friend who set his tables up correctly but I am missing some data. When I print the data array what I expect is this: …
huzzah
  • 1,793
  • 2
  • 22
  • 40
0
votes
1 answer

CakePHP multiple scopes

I have CakePHP 1.3 multiple tree in the table and for moveup and movedown i set $this->Category->Behaviors->attach('Tree', array( 'scope' => array( 'Category.parent_id' => $node['Category']['parent_id'], ), …
Constantin.FF
  • 687
  • 1
  • 10
  • 23