如何在我登录后在其他页面控制器中找到我当前的用户ID? [英] how to find out my current user id in other page controller after i login?

查看:555
本文介绍了如何在我登录后在其他页面控制器中找到我当前的用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算在我的事件索引页面上设置权限,只允许某些用户查看我添加事件时设置的权限。在用户点击我的事件之后,事件控制器将首先检查用户ID并检查事件数据库,该控制用户可以在他的日历中看到哪个事件。当用户创建事件并与其他用户共享时,将添加权限。除此之外,我如何找到当前用户ID与我的事件数据库进行比较,这是准确的1?



任何建议我做这个功能?
i需要知道代码和概念如何获取当前用户id与所有事件数据库进行比较,并允许当前用户查看特定事件。



解决方案

获取登录用户数据的推荐方法是通过AuthComponent本身:

  //在任何控制器中
$ userId = $ this-> Auth-> user('id');

查看访问登录用户 .cakephp.org / 2.0 / en / index.htmlrel =nofollow> CakePHP Book 。


i am planing to set a permission on my event index page, which just allow certain user to view which had set when i add the event. After user click into my event, the event controller will 1st check the user id and check the event database which control the user can see which event in his calendar. The permission is added when user create a event and share to other user. Beside, how can i find the current user id to compare with my event database which is the accurate 1?

any suggestion for me to did this function? i need to know the code and concept how i get the current user id to compare with all the event database, and allow the current user see the certain event.

thanks alot for your information.

解决方案

The recommended approach for getting logged in user data is via the AuthComponent itself:

// in any controller
$userId = $this->Auth->user('id');

See Accessing the logged in user in the Auth section of the CakePHP Book.

这篇关于如何在我登录后在其他页面控制器中找到我当前的用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆