为了在console命令中获取当前用户,我想将user_id传递给我的自定义控制台命令。
1.有没有办法实现这个?
2.还有其他好方法可以获得当前用户吗?
THX
答案 0 :(得分:1)
要通过命令行选择某个用户,您可以查看着名FOSUserBundle
的{{3}}:
protected function execute(InputInterface $input, OutputInterface $output)
{
$username = $input->getArgument('username');
// interact with the username.
像php app/console your:command username
一样调用命令。
答案 1 :(得分:0)
非常感谢@RoyalBg。我通过添加一个参数来解决问题。
->addArgument('user_id', InputArgument::OPTIONAL, 'The id of the current user')
然后我运行命令
php app/console ssss $userid
它有效。