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

Issue in update() function in sqlserver.php in CakePHP

We have developed our app in CakePHP running with MYSQL and this is working fine. PHP version is 5.4.16, Apache 2.4.4, latest XAMP. CakePHP version: 2.3.0 We already have similar Database in MSSQL also. Now we want to run our app with this MSSQL…
Garry
  • 1
  • 1
0
votes
2 answers

Can I use a dynamic model in variable settings?

I have this code $this->loadModel($model); $this->Task->id = $id; $this->Task->save($this->data[$model]); How can I setup the "Task" model so I can make it dynamic because this doesn't work: $this->loadModel($model); $this->$model->id = $id; …
Justin Young
  • 2,393
  • 3
  • 36
  • 62
0
votes
2 answers

Find all distinct field values for a Model that occur N times in CakePHP

So I have a model FeaturedListing that has a field date which is a mysql date field. There will be multiple FeaturedListings that have the same date value. I want to find all dates that have N or more FeaturedListings on it. I think I'd have to…
Mike
  • 147
  • 3
  • 10
0
votes
1 answer

Validating Multiple sets of POST data in Cakephp

I've got a Cakephp Project with an 'Addresses' table with the following structure: CREATE TABLE `addresses` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `name` varchar(50) NOT NULL, `company` varchar(50) NOT…
user782161
  • 63
  • 6
0
votes
1 answer

Validate associated models in CakePHP2

I'm a noob in CakePHP and I've been trying to do some complex validations here: I have the following models: - Fonts (name, file); - Settings(value1,value2,value3,type_id,script_id); - Types(name) Whenever I create a Font I also create a default…
iodonnet
  • 3
  • 3
0
votes
0 answers

Dynamic Controller to Save Multiple Models

I have the "admin" controller. In the add($model) function I want to add some data inside the $model. How can I do something like this: $this->$model->save($this->request->data); Is there a better way? Example: Add Function function add($model =…
0
votes
1 answer

CakePHP Join Model Issue

I have three relationships in my database, actions, action types and social media. Every action has an action type and the same action type can be shared by many actions. Also, every action belongs to a specific social media which can be shared by…
danielperaza
  • 412
  • 3
  • 12
0
votes
1 answer

Making CakePHP associations smarter

I have three models associated with each other in my CakePHP application. I have an Article which belongs to both a Category and an Author. I query for an category’s latest articles like this: $category = $this->Category->find('first', array( …
Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0
votes
0 answers

CakePHP find() on HABTM association table with missing model

I'm building an e-commerce site using CakePHP 2.3.x that has a Product model associated with an Order model in a HABTM relationship and I'm using orders_products as my join table. I have all of the associations working correctly and doing a find()…
0
votes
1 answer

CakePHP - Re-imported model and (i18n) translate with empty strings

The problem is that I import a model. App::import('Model', 'Carrier'); $this->Carrier = new Carrier; And I re-import and instacing this model later. Normally it would work as well. However, this is a multi-language site. And the second instacing it…
0
votes
2 answers

cakephp setting select options and values at Model

In my database model, my attribute is set as type INT. On the front end, I want to display a select field with representative values for the respective Integer values. eg: [1 = Home, 2 = About] I am currently using an external plugin for the…
na9090
  • 125
  • 2
  • 13
0
votes
0 answers

Returning a contained result in a hasMany find in CakePHP 2.x

I have a pretty straightforward Model relationship: a POST hasMany COMMENTs. They're both correctly related to each other and they both have the Containable attribute turned on. Is there any way to perform a find on POSTs and return an array of just…
oppositeday
  • 113
  • 1
  • 5
0
votes
1 answer

Manual JOIN on CakePHP

I'm trying to do manual join because I expected to get better query result than CakePHP did. This is my controller's coding $this->ClinicWishList->contain(); $this->set('recordSets', $this->ClinicWishList->find('all', array( 'fields' =>…
Artisan
  • 4,042
  • 13
  • 37
  • 61
0
votes
2 answers

How to show data from different related models in cakephp?

I'm fairly new to cakePHP and I'm trying to build a simple webapp. I have a 3 Models: Property, Operation and Category. My relationships are: Category -> hasMany -> Property Operation -> hasMAny -> Property each property has a foreign key for the…
sebastianb
  • 13
  • 10
0
votes
1 answer

Saving current view id 14 in /localhost/topp/events/view/14 to comments table field

Trying to save the current event id '14' in the url '/localhost/topp/events/view/14' to a event_id field in a comments table. I am using the add function in the comments controller and an 'add comment' button on the events view.ctp page. Any ideas?…
Joshua
  • 371
  • 2
  • 6
  • 23