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 multiple insert from a form

I have a site in cakephp 2.2, and I have a form with many input type text with a value taken from a query. I want when I save with a submit button to create for every input text a new record into my table in my database. First of all I have make a…
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
0
votes
1 answer

CakePHP: fetch related records in order?

I have two models: Event and Match. An event can have many matches. My Match model has $order = array('match_order' => 'asc'). The match_order column in my matches database table is just a simple INT column to order matches. I have a controller…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0
votes
4 answers

cakephp getting value of textfield in model

Hi I have dynamically added input fields on my add view. When I submit my form I want all them input fields to be concatenated into one string and stored in a single database field. Im trying to achieve this using the beforeSave method of cakephp…
Schokea
  • 708
  • 1
  • 9
  • 28
0
votes
1 answer

Confusion with HABTM IN Cakephp

I have 3 tables structure as... SONG(id, status) TRACKLIST(id, song_id, artist_id, status) ARTIST(id, status) I wish to have HABTM so I mentioned as.. Song MODEL var $hasAndBelongsToMany = array( 'Artist' => array( 'className' =>…
Tisha
  • 13
  • 4
0
votes
1 answer

CakePHP cannot create multiple 'hasMany' items from a model on afterCreate()

In a CakePHP project, I have a User class and a Category class. A User hasMany 'Category' and Category belongsTo 'User'. When I create a user, I d like to create a coupla categories by default for the new user. But for some reason, only one new…
walmik
  • 1,440
  • 2
  • 13
  • 30
0
votes
1 answer

Php Variable in Cakephp Model

I am trying to use join with two table by using has many relation of CakePHP with condition my model code are here which am using public $userid = 3; public $name = 'Course'; public $hasMany = array( 'Enrollcourse' => array( …
M_A_K
  • 378
  • 3
  • 16
0
votes
1 answer

cakephp primay key cant be used for user login

Im having a weird issue. My employee table has id->int(11) as primary key. It also has code->varchar(36), password and some other fields. This code and password are the two fields employees use to login to the system. I used cakePHP form helper to…
Ivin
  • 4,435
  • 8
  • 46
  • 65
0
votes
1 answer

How to display differnt field other than id when using Associations and baking cake

I'm using Associations to Link Models together in CakePHP. I have a Player model that is linked to a Statistic model using a $hasMany relationship. So basically one player can have many statistics. After I set up these relationships, I use cake bake…
bigmike7801
  • 3,908
  • 9
  • 49
  • 77
0
votes
2 answers

CakePHP. Do not works "on => create"

I set up rule 'isUnique' and set 'create' value for 'on' option. Complete code: 'username' => array( 'notempty' => array( 'rule' => array('notempty'), 'message' => 'Empty field', 'required' => true, ), …
Scofield
  • 4,195
  • 2
  • 27
  • 31
0
votes
1 answer

cakePHP HABTM don't save

I have looked into all threads I could find about this Topic, but nothing solves my Problem. I have a 'customers' table and an 'employees' table which should be connected via the 'customers_employees' table. In my Form I can select the employees,…
blacksheep_2011
  • 1,083
  • 3
  • 11
  • 22
0
votes
1 answer

How do I add multiple related records programmatically in a HABTM CakePHP relationship scenario?

I've got my models set up so that Users belong to Groups. There is a working HABTM relationship between these two. The code below is used to populate the database with some demo data. Prior to the following snippet, the Groups table has been filled…
Ralf
  • 2,512
  • 4
  • 24
  • 26
0
votes
1 answer

cakephp relations model

I have a site developed in CakePHP 2.0. I have a database with many tables and I want to relation two tables. I have done this many times, but with two tables I can't do this and I don't know why. This is my two tables: ingredient_aliases: id …
user1427811
0
votes
1 answer

Cakephp: Saving data already saved in one table to another table in cakephp

Hie guys, im seeking your help. An applicant applies for a place and the details are saved in the applicants table and is given a default status of waiting. The administrator accepts applicants form waiting to either accepted or denied. When a…
alicemap
  • 43
  • 1
  • 10
0
votes
1 answer

Cakephp: Validating an input field depending on an option selected from a dropdown list

Hie guys i need help with my code I don't know how to do it. I have a form where a student selects an exam body, if the exam body selected is zimsec marks should be empty and if the exam body is cambridge marks should not be empty and should take a…
alicemap
  • 43
  • 1
  • 10
0
votes
1 answer

cakePHP find not respecting belongsTo association

I am having a problem getting a model->find() call to respect a belongsTo association I built. Here is the association: var $belongsTo = array('User' => array('className' =>'User', 'foreignKey' => 'id', …
Lee Loftiss
  • 3,035
  • 7
  • 45
  • 73