我正在尝试手动创建用户。但是我得到了以下错误。基本上它将post值返回为null
执行'INSERT INTO用户时出现异常(用户名,username_canonical,email,email_canonical,enabled,salt,password,last_login,locked,expired,expires_at,confirmation_token,password_requested_at,roles,credentials_expired,credentials_expire_at,name,surname,company )VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'与params [null,null,null ,null,1,“48vgaw6nv7y8kk48kwo4k8o4os44c4c”,null,null,0,0,null,null,null,“a:0:{}”,0,null,null,null,null]:
SQLSTATE [23000]:完整性约束违规:1048列 'username'不能为null
这是我的代码
/**
* @Route("/add-user", name="add-user")
*/
public function AddUserAction(request $request)
{
$userManager = $this->container->get('fos_user.user_manager');
$name=$request->request->get("name");
$surname=$request->request->get("surname");
$comapany=$request->request->get("company");
$username=$request->request->get("username");
$password=$request->request->get("password");
$email=$request->request->get("email");
$tel=$request->request->get("tel");
$mobile=$request->request->get("mobile");
$role=$request->request->get("role");
$user = $userManager->createUser();
$user->setUsername($username);
$user->setEmail($email);
$user->setPlainPassword($password);
$user->setRoles(array($role));
$user->setEnabled(true);
$userManager->updateUser($user);
return $this->redirect($this->generateUrl('index'));
}
答案 0 :(得分:0)
我找到了。我输入错误的表单名称...抱歉打扰你们......