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: How to validate an array to make sure that it has at least five items or more

Hie guys i need help with my code. I have a form where a student selects subjects, marks and grades they obtained. Subjects and grades are a dropdown menu and they are in a loop. I want a student to enter at least five subjects including english…
alicemap
  • 43
  • 1
  • 10
0
votes
2 answers

Dynamically passing a model name to a CakePHP Plugin

I'm having trouble wording my problem, so it's been tough to search for an answer. Hopefully you'll know how to help. I am creating a CakePHP 2.1 Plugin that will interact with a series of its own Models: - Friend - Group - User Friend and Group…
Dustin
  • 846
  • 8
  • 13
0
votes
1 answer

CakePHP date modification, ex: old_date +1day

I am using CakePHP2.1.3, and I have two dates. The first is a start date set through an add model form and I want to keep that one. The second I want to be generated from a variable based on a previous choice. I pulled the variable out, so that's…
user1230790
  • 73
  • 1
  • 10
0
votes
1 answer

CakePHP User Lookup based on their ID

I thought this would be a relatively common thing to do, but I can't find examples anywhere, and the Cookbook's section on find() was not clear in the slightest on the subject. Maybe it's just something that's so simple Cake assumes you can just do…
joshdcomp
  • 1,618
  • 3
  • 19
  • 26
0
votes
3 answers

cake php auto select foreign keys when editing

I am using Cake PHP with scaffolding. I'm having a problem with the code that it generates and want to see if there is a way around it of if I should end up building custom views. Lets say that I have two models Tests and Questions. Tests can have…
majestiq
  • 545
  • 8
  • 25
0
votes
3 answers

Cake Php Read function to retrieve result as 1-Dimensional array

Cake Php Read function to retrieve result as simple array $result = $this->Model->read('id, name, title', $id); It will result as Array ( [Model] => Array ( [id] => 1 [name] => test [title] => New Head title …
Justin John
  • 9,223
  • 14
  • 70
  • 129
0
votes
2 answers

Model (reference) behaving strange in Controller

I'm having a strange issue with a CakePHP 2.1.1 Project. The issue is that if I call a find() on the Competition model (in the following code), right after it I call a custom method in another model the operation fails with the following…
Borislav Sabev
  • 4,776
  • 1
  • 24
  • 30
0
votes
2 answers

cakephp change language on fly

My site is in 2 languages (english and italian) My SiteMessagesController.php controller code: public function index() { $this->SiteMessage->locale = 'it'; $this->SiteMessage->recursive = 0; $this->set('siteMessages',…
gautamlakum
  • 11,815
  • 23
  • 67
  • 90
0
votes
3 answers

CakePHP: hasMany with join table

I have two models: Store and Review. Users of my site can leave a review on a store. In my database, I have a join table, reviews_stores that associates a review with a store. How do I link my models? I assume a Store should haveMany Review, and a…
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0
votes
1 answer

cakephp tree model structure

I want to get a tree of Categories to show it like this: cat1 subcat1 subcat2 subcat3 subsubcat1 cat2 subcat1 ... I have this table: CREATE TABLE IF NOT EXISTS `kategorie` ( `id` int(11) NOT NULL auto_increment, `name`…
user606521
  • 14,486
  • 30
  • 113
  • 204
0
votes
4 answers

Data validation in CakePHP doesn't work

I don't know why this doesn't work (I am using CakePHP 2.1 and also tried 2.0): Here is Model class User extends AppModel { public $validate = array('username' => array('rule' => 'email')); } Here is Controller class UsersController…
user606521
  • 14,486
  • 30
  • 113
  • 204
0
votes
2 answers

CakePHP: paginating with search logic in a model

I'm having trouble paginating a search result. My setup is as follow. I have a search form at myapp.com/searches/products with view (has search form) .../app/views/searches/products.ctp. I am employing a Searches controller that uses the Product…
laketuna
  • 3,832
  • 14
  • 59
  • 104
0
votes
1 answer

Virtual Fields as aliases to other Model field - SQL: Unknown Column Error

I'm new to an existing Cake project where we are trying to use a virtualField within a model to alias another model field. In Context: class Product extends AppModel { var $name = 'Product'; var $hasOne = array('ProductPrice'); var…
RC.
  • 27,409
  • 9
  • 73
  • 93
0
votes
1 answer

AppModel aftersave, get controller function name

I'm trying to log every write operation so I'm using the afterSave and afterDelete callbacks in AppModel. Basically I need to log(for the moment): the model , the controller function, the loggedin user data and the remote ip It seems that I was able…
slacky
  • 101
  • 1
  • 2
  • 8
0
votes
2 answers

Using multiple database tables in CakePHP

In my application, i have many methods that my controllers use commonly. At first i copied them to controllers, then i found out that i must put them in AppController. So i. reach those methods from derived controllers by "$this->commonmethod" The…
trante
  • 33,518
  • 47
  • 192
  • 272