後,我有一個用戶控制器,在那裏,如果我增加一個用戶我想根據用戶選擇上,他的賬戶重定向條件,保存記錄
形勢的用戶類型來重定向:
用戶表
ID
名
usertype_id
用戶添加表單具有用戶類型的選擇框,如果用戶選擇教師,我有兩種類型的用戶:教師和學生(每個表格,模型,控制器),我想重定向到/ teachers/add/$ id如果用戶選擇學生,我想重定向到:/學生/添加/ $ ID
這是我有個大氣壓,但並不明顯工作
<?php
class UsersController extends AppController {
var $name = 'Users';
function add() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$id = $this->User->id;
if ($this->User->usertype_id=='1')
{
$this->redirect(array('students/add/'.$id));
} elseif ($this->User->usertype_id=='2') {
$this->redirect(array('teachers/add/'.$id));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
}
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
}
}
$usertypes = $this->User->Usertype->find('list');
$this->set(compact('usertypes'));
}
}
?>
謝謝,只是你必須知道我猜。我想我搜索了121324種不同的東西來找到正確的方法來做到這一點,沒有任何結果。你讓我的一天:) – Weptunus 2010-10-30 14:07:46
不客氣! – Stephen 2010-10-30 23:45:20