为了在控制台命令中获取当前用户,我想将user_id传递给我的自定义控制台命令。
1.有办法实现这一点吗?
2.或者有其他好方法可以获得当前用户吗?
Thx
要通过命令行选择某个用户,可以查看著名的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
它是有效的。