我计划在我的事件索引页面上设置权限,这只允许某些用户查看添加事件时设置的内容.用户单击进入我的事件后,事件控制器将首先检查用户ID并检查事件数据库,控制用户可以在其日历中查看哪个事件.用户创建事件并与其他用户共享时添加权限.除此之外,我如何找到当前用户ID与我的事件数据库进行比较,这是准确的1?
我有什么建议去做这个功能吗?我需要知道代码和概念如何获取当前用户ID以与所有事件数据库进行比较,并允许当前用户查看特定事件.
非常感谢您的信息.
nei*_*kes 20
登录用户数据的推荐方法是通过AuthComponent本身:
// in any controller
$userId = $this->Auth->user('id');
Run Code Online (Sandbox Code Playgroud)
请参阅CakePHP Book的Auth部分中的访问登录用户.
使用会话在页面之间为用户保存和读取数据.
在控制器内:
// store a user id in the session
$this->Session->write('User.id', $userId);
// read a user id from the session
$userId = $this->Session->read('User.id');
Run Code Online (Sandbox Code Playgroud)
视图内:
// read a user id from the session
$userId = $session->read('User.id');
Run Code Online (Sandbox Code Playgroud)
如果你喜欢"User.id"之外的东西,你可以使用你想要的任何键.我只是使用它,因为AuthComponent如果你使用它是默认值.