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