I have 2 db tables
: Users & Projects.
Fields of Users table are : id, name, username, password, email, address, phone.
Fields of Projects table are : id, name, description, user_id, deadline, budget.
What I need is that, I'll have 1 form, where there will be all fields from these 2 tables. And, when I submit the form, these fields will be saved in these 2 tables.
For example, my form will be like this :
<?php
echo $this->Form->create('User');
echo $this->Form->input('name',array('type'=>'text','div'=>false));
echo $this->Form->input('username',array('type'=>'text','div'=>false));
echo $this->Form->input('password',array('type'=>'password','div'=>'false));
echo $this->Form->input('email',array('type'=>'email','div'=>false));
echo $this->Form->input('address',array('type'=>'textarea','div'=>false));
echo $this->Form->input('phone',array('type'=>'tel','div'=>false));
echo $this->Form->input('name',array('type'=>'text','div'=>false));
echo $this->Form->input('description',array('type'=>'text','div'=>false));
echo $this->Form->input('deadline',array('type'=>'date','div'=>false));
echo $this->Form->input('budget',array('type'=>'num','div'=>false));
echo $this->Form->submit('Save');
echo $this->Form->end();
?>
Now, I want that when I submit the form, the fields will be saved in the corresponding tables; Users
table will receive & save its fields, and Projects
table will receive & save its fields.
For this, I tried hasMany
association between Users
& Projects
tables, means, each user from Users
table will have many projects from Projects
table.
In User.php
, I tried this :
class User extends AppModel{
public $hasMany=array(
'Project'=>array(
'className'=>'Project')
);
}
I thought it'd work, but it didn't, only Users
table get its values, no value goes to Project
table. What is the problem here ? What should I do ?
Thanks.