0
訪問記錄
我只是想知道是否有這樣做的蛋糕,而不是寫代碼的邏輯我自己(雖然它不會是困難的,它可以快速/有效的方法只是有點不潔)。驗證,如果一個用戶應該能夠在CakePHP中
假設你有一個正常的users
表,然後posts
表。每個用戶都可以有很多職位和user_id
在posts
鏈接到users
的id
。
本教程顯示了編輯工作記錄這樣:
function edit($id = null) {
$this->Post->id = $id;
if (empty($this->data)) {
$this->data = $this->Post->read();
} else {
if ($this->Post->save($this->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect(array('action' => 'index'));
}
}
}
什麼是有效的檢查,最好的辦法,user.id
= post.user_id
沒有做的,如果檢查,然後重定向了。我實際上想要「綁定」/「限制」頁面,以便傳遞給edit()
的$id
是他們在posts
表中創建該書籍(或至少是當前「所有者」)的頁面。
更簡潔,我的問題是:什麼是的蛋糕版本:
$this->Post->read();
if ($this->Post->data['Post']['user_id'] != $my_current_user_id){
// Redirect
}
(僞代碼,但我希望它給的想法)。我已經通過文件拖網,但我似乎無法看到這(對我來說,它只是「有意義」它的存在給圖書館的其餘如何真棒是他們爲你做什麼用最少的工作)。