logged in user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peterberlin
    Active Community Member
    • Mar 2015
    • 1004

    logged in user

    Hello,
    what is the name of the variable that contains the name or ID of the logged in user in ESPO?​
    peter
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    what do you mean ? front-end or back-end ?
    Rabii
    Web Dev

    Comment

    • peterberlin
      Active Community Member
      • Mar 2015
      • 1004

      #3
      front-end

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        you can get the current user using this.getUser() or even you can get id using this.getUser().id

        Hope this helps
        Rabii
        Web Dev

        Comment

        • peterberlin
          Active Community Member
          • Mar 2015
          • 1004

          #5
          Many thanks for the info.​

          Comment

          • armen
            Junior Member
            • Aug 2021
            • 20

            #6
            Hi and what about back-end logged user variable, can you tell ?

            Comment

            • rabii
              Active Community Member
              • Jun 2016
              • 1250

              #7
              One needs to use a constructor injection to inject the User entity \Espo\Entities\User $user as a constructor parameter and then

              PHP Code:
              private User $user;
              
              public function __construct(
                      User $user
                  ) {
                      $this->user = $user;
                  }
              // Then access the user​
              $this->user->getId() 
              
              Last edited by rabii; 02-02-2024, 09:32 PM.
              Rabii
              Web Dev

              Comment

              • yuri
                Member
                • Mar 2014
                • 8440

                #8
                I want to note again. $this->getUser() is just a wrong answer. One needs to use a constructor injection to inject the User entity. As we almost don't use class inheritance in Espo, $this->getUser() is not relevant.
                Last edited by yuri; 02-02-2024, 04:41 PM.
                If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                Comment

                Working...