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

Dynamically populating the dropdown menus in PHP Cake. Access Model from another Model?

I am building a Cake PHP application. Different users have different properties so I use two objects to store a user for example User hasOne Student / Student belongs to User User hasOne Lecturer / Lecturer belongs to User The profile edit page…
Connel
  • 1,844
  • 4
  • 23
  • 36
0
votes
1 answer

Column not found, retrieving data associated model

I've got the following find() function $this->User->find('all',array( 'conditions' => array('User.id' => $this->Auth->user('id')), 'fields' => array('User.id','UserRole.id') )); And the following associations are defined //…
Martijn Thomas
  • 861
  • 3
  • 13
  • 24
0
votes
1 answer

CakePHP 2.X: HABTM with Bookmarks / Tags, saving from same form

I'm trying to build a simple bookmarking site as a project to learn some CakePHP, but am having significant trouble figuring out how to do HABTM (or whatever I might need) for Bookmarks/Tags. I have a simple form which has the fields 'Title', 'Url',…
Yair
  • 182
  • 2
  • 10
0
votes
1 answer

CakePHP print information from Model after delete

I'd like to set a message that prints a confirmation for the user, i.e.: "Thank you for deleting XYZ". At the moment my delete() method looks like this: public function delete($id) { if ($this->request->is('get')) { throw new…
Tamas
  • 10,953
  • 13
  • 47
  • 77
0
votes
1 answer

CakePHP 2.3 - Saving Related Model Data

I am trying to follow the conventions in the cookbook but am having no luck. I baked all of my CRUD and Model Associations and need to customize the Administrator Add View (Administrator Has 1 User). When I try and validate, I am getting the…
Randy Gonzalez
  • 445
  • 5
  • 17
0
votes
2 answers

How can I change the way cakephp passes the data for an associated model?

I've tried searching for an answer to this, as I'm sure its something that's been sorted out before, but I couldn't find anything discussing how cakephp formats the data returned from a Model. Normally I just see how the data comes, and handle it…
Randy Shelford
  • 142
  • 1
  • 7
0
votes
3 answers

cakephp: get values from a "cat" table in the "users_controller.php" file?

i have table "User" and a Controller "users_controller.php" and i have another table called "cateogry", need to retrieve values from this table in the "listall" action(site.com/users/listall). how can i get values from another table.
coderex
  • 27,225
  • 45
  • 116
  • 170
0
votes
2 answers

Error PDO Exception SQLSTATE[42000] when using CakeDC Users plugin

Iam using cakephp 2.2.1 and trying to use the cakedc users plugin, when I try to create a user I get the following error, can anyone give some tips or advice to resolve this error - I have loaded all tables using the migrations plugin. Thanks in…
Joshua
  • 371
  • 2
  • 6
  • 23
0
votes
1 answer

Cakephp save data , check if belongs to authed user

this is how it looks: URL: /Category/Edit/(category.id) Controller: loads info from category and puts it into the edit form -> Submit form & then you have: $this->Category->id=$id; $this->Category->save($this->request->data); Because it gets the id…
Lorenz V.
  • 558
  • 5
  • 12
0
votes
1 answer

SQL query to cakePHP format (invalid json result)

Hello I have a PostgreSQL query that I would like to write using cakePHP format SELECT id, title, author, postdate, postcontent, userID FROM posts WHERE userID = 12 AND id IN (SELECT articleID FROM favourites WHERE…
OussamaLord
  • 1,073
  • 5
  • 28
  • 39
0
votes
1 answer

CakePHP: variable sources for virtual field

Each Order has fields 'from_str' and 'from_bldg'. In Order model I created virtual field "from" that concatenates these fields: public $virtualFields = array( 'from' => 'CONCAT(Order.from_str, " ", Order.from_bldg)' ); However, Order has also a…
Gizzat
  • 39
  • 6
0
votes
1 answer

CakePHP Containable doesn't return correct results in "has many" relation

Someone can tell me why it doesn't work: $data = $this->Question->find('all', array( 'conditions' => array( 'Question.id' => $qid …
Ziemo
  • 941
  • 8
  • 27
0
votes
1 answer

How to write associated linking for a model?

Let's say I have a "users" table with a field called "user_type", for simple explanation if user_type is "C" this user is a clinic's owner, if user_type is "D" this user is a dentist. I would like dentists in this system belong to clinics which…
Artisan
  • 4,042
  • 13
  • 37
  • 61
0
votes
3 answers

can't update an existing record in CakePHP

i write a edit function to update user's info, my code: if($this->request->is('post')){ $this->request->data['User']['password']=Security::hash($this->request->data['User']['password'],'sha1', Configure::read('Security.salt')); …
Makio
  • 465
  • 6
  • 15
0
votes
1 answer

CakePHP: Multiple links to same model

Lets say each book has AuthorA and AuthorB fields. Both fields are foreign keys for authors table. table authors with fields: id | name table books with fields: id | name | a_author_id | b_author_id | How should controller, model and view be set up…
Gizzat
  • 39
  • 6