how to find out my current user id in other page controller after i login?

后端 未结 5 549
离开以前
离开以前 2021-02-06 12:30

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 cont

5条回答
  •  旧巷少年郎
    2021-02-06 12:43

    Use sessions to save and read data for a user between pages.

    Within Controllers:

    // 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');
    

    Within Views:

    // read a user id from the session
    $userId = $session->read('User.id');
    

    You can use any key you want if you prefer something over "User.id". I simply use this since it is what the AuthComponent defaults to if you are using that.

提交回复
热议问题