cakephp read and display from more than one related table
- by z22
I have 2 tables Users and Artists.
User:
id
name
password
city_id
state_id
country_id
Artist:
id
user_id
description
I wish to create add and edit form(single form acts as add and edit). But on click of edit link, I wish to fill in the form fields from user as well as artist table. How do i do that? Below is my controller code:
public function artist_register() {
$this->country_list();
if ($this->request->is('post')) {
$this->request->data['User']['group_id'] = 2;
if ($this->{$this->modelClass}->saveAll($this->request->data)) {
$this->redirect(array('controller' => 'Users', 'action' => 'login'));
}
}
$this->render('artist_update');
}
public function artist_update($id) {
$artist = $this->{$this->modelClass}->findByuser_id($id);
$artist_id = $artist[$this->modelClass]['id'];
if($this->request->is('get')) {
$this->request->data = $this->{$this->modelClass}->read(null, $artist_id);
$this->request->data = $this->{$this->modelClass}->User->read(null, $id);
} else {
if($this->{$this->modelClass}->save($this->request->data)) {
$this->Session->setFlash('Your Profile has been updated');
$this->redirect(array('action' => 'index'));
}
}
}
The code doesnt work. how do i solve it?