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
2
votes
2 answers

CakePHP 1.3 validation errors not showing with numerical indexed array

I've looked at loads of forums about validation errors not showing and tried various things but to no avail... Basically, the validation is correctly recognising the fields do not have values when they should, however the error messages don't…
weedave
  • 237
  • 1
  • 7
  • 22
2
votes
4 answers

CakePHP not pulling rows over a certain number for hasOne relationship

I have a client with a database that has several sizeable and interrelational models. We've come across an odd "bug" in a $hasOne relationship we're producing. The problem is this: The model UsersItems has a $hasOne relationship with Users. It is as…
dclowd9901
  • 6,756
  • 9
  • 44
  • 63
2
votes
2 answers

cakephp model association/join with same table

I have a table that contains parents and children. I want to be able to build the model so that it returns the parents and their children i.e it associates with itself. ID Name ParentID 1 Parent 0 2 Child1 1 3 Child2 1 4 Parent2 0 5 Child3 …
madphp
  • 1,716
  • 5
  • 31
  • 72
2
votes
1 answer

Custom model function to insert a new record in cakephp 3

I'm new to CakePHP. I have a table to keep record of user's activity by creating a log in it. The table has two columns +----+------------+-----------+ | id | user_id | comment | +----+------------+-----------+ I want to pass values from…
2
votes
2 answers

CakePHP: where to put shared model logic?

I'm working on a legacy CakePHP project (CakePHP 1.3) and I'm having a hard time figuring out where to put shared model logic. I come from a Laravel background and would normally make a service class or Laravel facade and use it where needed, but…
revolt_101
  • 395
  • 3
  • 12
2
votes
2 answers

Is it better to import controllers or models in CakePHP?

In a CakePHP application, is it better to import Controllers that have access to models or the Models themselves?
chustar
  • 12,225
  • 24
  • 81
  • 119
2
votes
1 answer

CakePHP use 3 models with saveAll

I have following situation: I'm developing an address-application to store the details of our clients. I've got the following db-structure: Clients hasMany Addresses Addresses belongsTo Client Addresses hasMany AddressEmails and AddressPhones If…
Tim
  • 5,893
  • 3
  • 35
  • 64
2
votes
1 answer

Display font icons near checkboxes in HABTM

I have 4 tables. properties, characteristics, characteristics_properties, characteristic_translations. Properties HABTM characteristics and Vice Versa. Also characteristics has many characteristic_translation and characteristic_translation belongs…
Johnny
  • 175
  • 1
  • 9
2
votes
2 answers

CakePHP 3 Saving HasOne association

possible bug in cakephp framework but not sure about that I got following MySQL InnoDB tables: database.users +-----+---------------+----------+ | id | user_group_id | username | +-----+---------------+----------+ | INT | …
2
votes
3 answers

CakePHP useDbConfig not working?

So i have my database.php as follows: public $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'SOMEHOST', 'port' => 8889, 'login' => 'LOGIN', 'password' => 'PASSWORD', 'database' =>…
Pbal
  • 185
  • 14
2
votes
1 answer

Replacement for AppModel in Cakephp3

I would like to implement an autoslug-function for two models in CakePHP3 and use the beforeSave-callback for that which works fine. However the slug structure is a bit different than in Inflector::slug, so I wrote a small function for the different…
harpax
  • 5,986
  • 5
  • 35
  • 49
2
votes
3 answers

What's the most efficient way to get data from a model in CakePHP?

I'm new to CakePHP, and still figuring out the basics. Right now I'm a bit mystified by the process to get one or more fields from a model (from inside another linked model). So far, I have this: $this->user->id = 123; $this->User->read(); $field1 =…
Tijmen
  • 149
  • 1
  • 6
2
votes
1 answer

cakePHP- retrieving from database. Models Associations & database

I feel pretty darn dumb for asking this question but I'm baffled, probably because I'm slightly intimidated with cakePHP(new to it, and not very comfortable),but its merits are practically forcing me to use it. So please if you could help, I…
LogixMaster
  • 586
  • 2
  • 11
  • 36
2
votes
5 answers

cakephp: saving to multiple models using one form

I have one form that saves a person with many parts and many colors but it's not saving the parts and the colors; only saving the person(main model). On my list view, part of script: echo $this->Form->input('Person.person_name', array('required' =>…
Leah
  • 225
  • 2
  • 10
  • 24
2
votes
0 answers

CakePHP model association not working inside plugin

By using the CakePHP 2.4 framework i'm trying implement a Admin site and Json Plugin for access it's content data. So, simply i used bake commands and created the admin site and plugin for it. Model class created for site only(app) not for the…
NMW
  • 33
  • 7