我有 2 张表用户和艺术家。
User:
id
name
password
city_id
state_id
country_id
Artist:
id
user_id
description
我希望创建添加和编辑表单(单个表单充当添加和编辑)。但是在单击编辑链接时,我希望填写用户和艺术家表的表单字段。我怎么做?下面是我的控制器代码:
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'));
}
}
}
代码不起作用。我该如何解决?