2015-10-16 24 views
0

用戶信息作爲它在文檔中說,我想修改信息由find()方法使用beforeFind()方法回調返回。CakePHP的3.X檢索內beforeFind

您可以使用此回調來限制基於 用戶角色的查找操作,或基於當前負載進行緩存決策。

但我實際上不知道如何檢索模型內的用戶信息。例如:

public function beforeFind(\Cake\Event\Event $event, Query $query, $options, $primary) { 
    $query->where(['society_id' => $user->society_id]); 
} 

感謝您的時間。

+1

而「_user_」是指當前認證的用戶? – ndm

+0

你看過這個[link](http://book.cakephp.org/3.0/en/controllers/components/authentication.html#accessing-the-logged-in-user)嗎? – Ray

+0

@ndm,是的,我的意思是當前用戶。 – Zat42

回答

2

的越來越登錄的用戶在你的表回調,最好的辦法是使用足跡插件:

https://github.com/usemuffin/footprint

如果你在你的debug($options)beforeFind()會看到有用戶信息。

+0

易於安裝和使用,謝謝。 – Zat42