I am new in CakePHP, developing a cloud application using CakePHP 2.5.1 and MySQL. i have following tables:
users
user_id ,
people_id(FK- people.people_id),
username,
password
people
people_id,
manager_id(FK- people.people_id),
firsr_name,
last_name,
roles
role_id ,
people_id (FK- people.people_id),
role
addresses
address_id,
people_id (FK- people.people_id),
street,
house no,
post code,
city
Foreign key people.manager_id
refers to primary_key people.people_id
. The field roles.role
can hold either 'manager'
or 'customer'
.
Now, in my registration form, there will be following input fields:
-username
-password
-first name
-last name
-street
-house no
-post code
-city
-role
I have used a User model (User.php), a registration form (add.ctp) and a controller (UsersController.php) to input username and password; and implemented login, logout.
The View add.ctp
:
<div class="users form">
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend><?php echo __('Registrierung'); ?></legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('password_confirm', array('label' => 'Confirm Password', 'maxLength' => 255, 'title' => 'Confirm password', 'type'=>'password'));
);
?>
</fieldset>
<?php echo $this->Form->end(__('Register')); ?>
</div>
is working fine. Now I need to include above input fields in the registration form. This means creating models for each table and defining the associations like belogsTo
, hasMany
, etc. in my User
model, I have defined the following association:
class User extends AppModel {
public $belongsTo = array(
'Person' => array(
'className' => 'Person',
'foreignKey' => 'people_id'
)
);
}
However, it throws the following error:
Database Error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Person.id' in 'on clause'
Could anyone tell me how to implement these associations? I could not find any example which matches with my requirements.