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

In CakePHP, what's the proper way to get data from different models into a view?

Example: I have models Post, Comment and User. I want to display the recent posts, comments and users on the home page. Which controller should be used? Can a single controller query multiple models, even if they are not related? Who is responsible…
Schrute
  • 711
  • 7
  • 15
0
votes
1 answer

CakePHP model to web service

I'm developing a web application that doesn't need database. All data comes via REST. My question is: Is possible to use a model class (extended from AppModel) to manage data from a RESTfull service?, How to do that?, Does CakePHP any way to mapping…
Lobo
  • 4,001
  • 8
  • 37
  • 67
0
votes
2 answers

Cakephp Best Practices

I have a question about best practices in CakePHP! Let's imagine the following situation: In a Receipt Model i have the code: public function beforeValidate() { $this->data[$this->name]["client_id"] = CakeSession::read("Auth.User.id"); …
0
votes
2 answers

CakePHP Model Name as Variable

I am using CakePHP 2. We can access a Model named 'Setting' as $this->Setting->find('all') however, how could i make the 'Setting' value a Variable. Something like $modelName = 'Setting'; $data = $this->{$modelName}->find('all'); Any help is…
Guns
  • 2,678
  • 2
  • 23
  • 51
0
votes
2 answers

What to do when Cake doesn't say what is wrong?

What to do when model does not save or return any type of error? $data = array( 'Model' => array( 'field1' => 'value1', 'field2' => 'value2', ) ); try { // Forget to add this $this->Model->set($data); if…
Gabriel Santos
  • 4,934
  • 2
  • 43
  • 74
0
votes
0 answers

Cakephp not able to save associated model

I've a model CloudApp which has HABTM relationship with Policy model e.g: class CloudApp extends AppModel { public $displayField = 'name'; public $hasAndBelongsToMany = array( 'Policy' => array( 'className' =>…
gauravphoenix
  • 2,814
  • 3
  • 25
  • 33
0
votes
1 answer

Multiple data array with the one set value

I have a cakephp application that i want to save posted to my base I'm using following code in controller : $ = $this->request->; $['Link']['url'] = (',',$['Link']['url']); $this->link->save($); var_dump : array(1) { ["Link"]=> array(2) {…
osos
  • 2,103
  • 5
  • 28
  • 42
0
votes
1 answer

Related models with conditions in cakephp

If I have two tables, in a has-and-belongs-to-many relationships (e.g. members and events), and a join table (e.g. MemberEvents), how do I specify that Events exist in a conditional relationship to members - that is, I want to select some group of…
DMCoding
  • 1,167
  • 2
  • 15
  • 30
0
votes
1 answer

CakePHP - Third Part Assignments

Sorry if the Title misses what i'm aiming at, but had no clue how to name this. Here's my Quest: I have a single Cart, holding multiple Items (1:n) which are belonging to prices (1:1). The Relations between Items and Prices are working as…
user2610087
  • 117
  • 3
  • 13
0
votes
1 answer

Cakephp HABTM association save not working

view.ctp Session->check('Auth.User.id')) { $userid = $this->Session->read('Auth.User.id'); } ?>

CMS scripting
  • 669
  • 1
  • 7
  • 13
0
votes
1 answer

Extend CakePHP Find Method

For my latest project I need to pull extra data from another data API (specifically Instagram) and display it alongside the user's stored database information. I'd like to do it in a way that hooks in nicely with the existing Cake database calls,…
moberemk
  • 1,597
  • 1
  • 18
  • 39
0
votes
1 answer

Cakephp joining two models on insert

OKay so i have two tables Employee and User my employee model looks like this: class Employee extends AppModel{ public $name = 'Employee'; public $primaryKey = "employee_id"; public $actsAs = array('Containable'); public…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
0
votes
1 answer

CakePHP working with two controllers / models

First of all i'm sorry about the name of this question i had a hard time figure out what to call it: Here is my problem i have the following two data tables: Users Employees. These two data-tables are connected in a 1 to 1 relationship Now both of…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
0
votes
4 answers

How to apply PHP function to a column returned from CakePHP query

In my controller I am retrieving records from my institutions table with the following fields $params = array( 'fields' => array( 'Institution.id', 'Institution.name', 'Institution.about', 'Institution.picture'), …
Speed Demon
  • 691
  • 1
  • 9
  • 21
0
votes
2 answers

Issue in cakephp when execute certain MSSQL stored procedure

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