Announcement

Collapse
No announcement yet.

logged in user

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

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

    Comment


    • #3
      front-end

      Comment


      • #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


        • #5
          Many thanks for the info.​

          Comment


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

            Comment


            • #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


              • #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.

                Comment

                Working...
                X