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
4
votes
3 answers

CakePHP using multiple databases for models

Is it possible for certain models to be in one database and other models in another (using the same connection)? I have a number of read-only tables that I want shared between multiple installations of my system. Other tables need to be…
nickf
  • 537,072
  • 198
  • 649
  • 721
4
votes
2 answers

How can I use Model functions correctly according to the MVC pattern in CakePHP?

Can I do this in a Controller: $this->User->read(null, $id); $this->User->find('list'); Is it correct? Am I using MVC correctly? Can these easy functions be used in a Controller? Or, do I need to create these functions in the Model? Like…
Patrick Maciel
  • 4,874
  • 8
  • 40
  • 80
4
votes
2 answers

Create a form with no relation to a model in cakePHP

I have a form that a user selects a document in. This document is then saved to the webroot folder by the controller. However, before it even shows the form, it gives me an error: Missing Database Table Error: Table office_layouts for model…
Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69
4
votes
4 answers

Fetch only some fields on find in CAKEPHP

My problem is when I fetch data of user from users table , all the fields of user table fetched from users table..but i don't want to include password and email address into that so is there any way to only fetch fields other than password and…
Meet Brahmbhatt
  • 57
  • 1
  • 1
  • 8
4
votes
1 answer

CakePHP alias breaks HABTM Model

Consider the following HABTM relation in CakePHP 2.2.3: class User extends AppModel { public $hasAndBelongsToMany = array( 'Role' => array( 'className' => 'Role', 'joinTable' => 'roles_users', …
Jay
  • 2,141
  • 6
  • 26
  • 37
4
votes
1 answer

cakephp query with many tables

I have a site developed in cakephp 2.0, I have some tables relationed here is an example: This is my relations: ingredients (id,name) has many versions ingredient_properties(id,property_id,version_id) belongs to properties, versions properties…
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
3
votes
4 answers

Every model, similar code - better way? (CakePHP)

In nearly every model, I end up writing code similar to the below example code. It checks to see if options like limit, order, conditions...etc are sent and changes the query based on that. Just seems like there MUST be a better way, since most of…
Dave
  • 28,833
  • 23
  • 113
  • 183
3
votes
3 answers

CakePHP model loading take a while

Why is App::import('*', '*');, as well as model loading takes as long as ~3-5ms? This is quite annoying when you have around 100 required models for a page; it'll take more or less 300ms just to load the core and the models. Furthermore, I saw that…
Sébastien
  • 1,667
  • 3
  • 20
  • 31
3
votes
7 answers

CakePHP Containable: Loading too much relations?

I'm a huge fan of cakephp's containable element, because I always thought, that it would handle loading of additional models appropriate. But in the last days I dug deeper and found out, that there's really an memory issue. Think of the following…
Johannes N.
  • 2,364
  • 3
  • 28
  • 45
3
votes
2 answers

How to specify database configuration in CakePHP 2.0.2?

I've just installed CakePHP 2.0.2 for use in a new project. I'm trying to use a database configuration called development but my model doesn't seem to be picking it up. Based on CakePHP 2's new directory and file name conventions, I've created the…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
3
votes
1 answer

cakephp - get table names and its column details

Does anyone knows how to get table name from model name? Also I want to get all column names and its types of that model/table name. Is it possible to get such details of given model name? Thanks.
gautamlakum
  • 11,815
  • 23
  • 67
  • 90
3
votes
2 answers

Condition in read() function CakePHP

In CakePHP function edit I use read() function as: $this->data = $this->Article->read(null, $id); It brings all fields of $id. Now, what I am trying to tweak to give one more condition in read() to get articles only if user logged in is related to…
Rikesh
  • 26,156
  • 14
  • 79
  • 87
3
votes
3 answers

CakePHP - $this->data disappears before Model::save

I have a page for editing records of the Venue model in my app. This page was working at some stage, but is now broken. in the controller action, debugging $this->data gives the expected array of form values. However, in the Venue model, debugging…
Will
  • 1,893
  • 4
  • 29
  • 42
3
votes
1 answer

CakePHP: Limit Fields associated with a model

I have several fields in some of my database tables that my CakePHP models never need to retrieve. Is there some way to set a default set of fields to fetch at the model level? For instance I retrieve some data from a third party designed database…
Ben Brocka
  • 2,006
  • 4
  • 34
  • 53
3
votes
2 answers

Bake Models - CakePHP - Ubuntu

I am currently trying to bake models for a project in CakePHP. I have set up my database tables and baked my skeleton project. I then execute the following via terminal: cake bake -app /home/gary/glecto/ Which then display's me the correct menu.…
GaryDevenay
  • 2,405
  • 2
  • 19
  • 41
1
2
3
33 34