我在加入车票不管是谁登录的问题,CakePHP的1.3这条线工作完全正常:$this->data['Ticket']['user_id'] = $this->Auth->user();
下面是完整的附加动作:如何在cakephp 2.0中登录的用户下添加门票?
public function add() {
if ($this->request->is('post')) {
$this->Ticket->create();
$this->data['Ticket']['user_id'] = $this->Auth->user();
if ($this->Ticket->save($this->request->data)) {
$this->Session->setFlash(__('The ticket has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The ticket could not be saved. Please, try again.'));
}
}
$users = $this->Ticket->User->find('list');
$this->set(compact('users'));
}
甚至没有现在的代码$this->Session->read('user_id');
作品。那么,两者中的任何一个都添加了票据,但user_id是空白的。任何帮助将不胜感激。
你调试的$这个 - 返回值> Auth->用户()?我怀疑这实际上是一个id,但是是一组键。使用pr()来找出实际返回的内容。 – mark
pr($ this-> Auth-> user('id'));返回1,这是登录的当前用户的正确ID。任何想法为什么ID未被保存? – Lyman