How to use more than one model in CakePHP controller

I created a registration form and submit the data to the controller.

I want to insert this data into 3 different tables (models).

How can this be achieved?

+3
source share
3 answers

As long as your forms are formatted in accordance with the CakePHP conventions, and the relationships between the models are configured correctly, this will be done automatically when called $this->Model->save($this->data).

0
source

What you mean (in CakePHP terms) is that you want to use more models than the default. The default model is the one called your controller.

, $uses . :

<?php
class ExampleController extends AppController {
    var $name = 'Example';

    // $uses is where you specify which models this controller uses
    var $uses = array('Model1', 'Model2', 'ModelN');

    // ... here go your controller actions (methods)

}
?>   

Model1, Model2 ModelN. .

, $uses , :

var $uses = array();

CakePHP , :

+18

" ", , .

$this->loadModel('Model1');

.

, . :

$this->Model1->Model2->find();

Containable and Relationships (HasMany, BelongsTo, HABTM)

0
source

All Articles