[英]pass parameter to custom console command symfony2
为了在控制台命令中获取当前用户,我想将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
这样的命令调用php app/console your:command username
。
非常感谢@RoyalBg。 我通过添加一个参数解决了这个问题。
->addArgument('user_id', InputArgument::OPTIONAL, 'The id of the current user')
然后我运行命令
php app/console ssss $userid
有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.