Repository navigation
Warning: Undefined array key "user_id" in vendor/lm-commons/lmc-user/src/Mapper/UserHydrator.php on line 77 #49
Description
Activity
@vrkansagara, this looks like you user table in your database does not have a
user_idcolumn.What is the schema for the user table in your database?
The
/datafolder provides example schemas to build the user table.@visto9259 I am trying to use LmcUser + LmcRbacMvc where I am getting this error. I have already configured using this way
'user_entity_class' => \User\Entity\User::class,<?php namespace User\Entity; use LmcUser\Entity\User as LmcUserEntity; use LmcRbacMvc\Identity\IdentityInterface; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use LmcUser\Entity\UserInterface; use Rbac\Role\RoleInterface; /** * @ORM\Entity * @ORM\Table(name="user") */ class User extends LmcUserEntity implements IdentityInterface { /** * @var int|null * * @ORM\Id * @ORM\Column(name="user_id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @var string * @ORM\Column(name="username",type="string", length=128, unique=true, nullable=true) */ protected $username; /** * @var string * @ORM\Column(name="email",type="string", length=128, unique=true, nullable=false) */ protected $email; /** * @var string * @ORM\Column(name="display_name",type="string", length=128, unique=false, nullable=true) */ protected $displayName; /** * @var string * @ORM\Column(name="password",type="string", length=128, unique=false, nullable=false) */ protected $password; /** * @var int * @ORM\Column(name="state",type="integer", unique=false, nullable=true) */ protected $state; /** * Get id. * * @return int */ public function getId() { return $this->id; } /** * Set id. * * @param int $id * @return UserInterface */ public function setId($id) { $this->id = (int) $id; return $this; } /** * Get username. * * @return string */ public function getUsername() { return $this->username; } /** * Set username. * * @param string $username * @return UserInterface */ public function setUsername($username) { $this->username = $username; return $this; } /** * Get email. * * @return string */ public function getEmail() { return $this->email; } /** * Set email. * * @param string $email * @return UserInterface */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get displayName. * * @return string */ public function getDisplayName() { return $this->displayName; } /** * Set displayName. * * @param string $displayName * @return UserInterface */ public function setDisplayName($displayName) { $this->displayName = $displayName; return $this; } /** * Get password. * * @return string */ public function getPassword() { return $this->password; } /** * Set password. * * @param string $password * @return UserInterface */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get state. * * @return int */ public function getState() { return $this->state; } /** * Set state. * * @param int $state * @return UserInterface */ public function setState($state) { $this->state = $state; return $this; } /** * @var Collection * @ORM\ManyToMany(targetEntity="\User\Entity\FlatRole") * @ORM\JoinTable(name="user_flatrole", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")}, * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")} * ) */ private $roles; public function __construct() { $this->roles = new ArrayCollection(); } /** * {@inheritDoc} */ public function getRoles() { return $this->roles->toArray(); } /** * Set the list of roles * @param Collection $roles */ public function setRoles(Collection $roles) { $this->roles->clear(); foreach ($roles as $role) { $this->roles[] = $role; } } /** * Add one role to roles list * @param \Rbac\Role\RoleInterface $role */ public function addRole(RoleInterface $role) { $this->roles[] = $role; } }
User table structure look like this.

For the roles issue, do you have a roles column in your table?
I don't see it the screen capture of the table structure that you shared above.That roles come from the relation , I think @visto9259
This patch should be needed here
public function hydrate(array $data, $object) { if (!$object instanceof UserEntityInterface) { throw new Exception\InvalidArgumentException('$object must be an instance of LmcUser\Entity\UserInterface'); } if (isset($data['id'])) { $data = $this->mapField('user_id', 'id', $data); } return $this->hydrator->hydrate($data, $object); }
looks like there is issue here https://github.com/LM-Commons/LmcUser/blob/master/src/Mapper/UserHydrator.php#L64
Hi @vrkansagara ,
I am still trying to reproduce the issues in my own dev setup.
Have you found a resolution or do you have more info to provide?
Are you using ORM for the user entities? Off the shelf, LmcUser does not use ORM for the user table. There is another module to use ORM for user https://github.com/LM-Commons/LmcUserDoctrineORM.
LmcUser when fetching users does not use ORM (I think) and since the roles come from the relation defined in your entity, roles do not get pulled into the user entity.yes, @visto9259 , I do confirm that I was not using LmcUserDoctrineORM. so facing this issue.
I also facing much difficult to setup the FlatRole using LmcUserMVC so can you consider to as proposal for the demo repository where it can show the working model for following packages.
- LmcUser
- LmcAdmin
- LmcRbacMvc
- LmcUserDoctrineORM
this combination is useful to show the basic Dashboard application so any one can easily start using this combination package and start creating application.
That would be a good idea but we lack the bandwidth to do so. This is all based on volunteer work.
I wrote a tutorial on the basics of how to use LmcUser: https://www.vistomedia.com/laminas-user-authentication-using-lmcuser/
Take a look. I intended to write a tutorial on LmcRbacMvc as a follow up but did not have the time to get to it.There are thousands of installs of LmcUser and LmcRbacMvc without issues. There could be bugs in the code but I suspect that there is something not set up properly in your application.
Can you share details on how you define the database adapter in your config? LmcUser uses the class
\Laminas\Db\Adapter\Adapter::classas the database adapter. You need a database config somewhere in your config files which I assume you have.
Please share yourlmc_userandlmc_rbacconfigs.@visto9259 , I figured out the issue as i said here. #49 (comment)
So this issue can be closed.
I have couple of improvement , I will make it PR
This is just the explanation for the warning and that I knew that the issue was where you pointed out.
You can submit a PR for it.
What about the other issues that you reported?
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🆕 New



I am using LmcUser + LmcRbacMvc with DoctrineOrmModule with MySQL
Composer.json
It has following settings