douzen1880 2017-10-05 15:16
浏览 84

来自php文件GetuserID的Symfony Session变量

i'm trying to add arrowchat, an tchat box from arrowchat.com And these file is just using php without using twig in my website and i don't know how to do for integrate this file with my session variable from twig.

This is what i need to do for integrate these file:

First, open the arrowchat/includes/integration.php file. This file must be customized to fit your specific website.

get_user_id() Function

The first and most important function to setup is the get_user_id() function. This function will simply return the user's ID or NULL if no user is logged in. The two most common ways to setup this function are by cookie and session.

Using a Session example:

function get_user_id() 
{
    $userid = NULL;

    if (!empty($_SESSION['userid']))
    {
        $userid = $_SESSION['userid'];
    }

    return $userid;
}

My problem is: It's not working and i think it's because $_SESSION['userid'] doesn't exist.

How can i do for take the user id from my session without using twig? I'm using FOSUserBundle for making the session when i connect to my website

Thanks all :)

  • 写回答

1条回答 默认 最新

  • duanfen9090 2017-10-05 15:21
    关注

    If you are into a controller you can do this with FOSUserBundle:

    $user = $this->getUser();
    
    if (null != $user) {
       $userid = $user->getId();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接