将参数传递给自定义控制台命令symfony2

时间:2013-08-09 09:18:36

标签: php symfony

为了在console命令中获取当前用户,我想将user_id传递给我的自定义控制台命令。

1.有没有办法实现这个?

2.还有其他好方法可以获得当前用户吗?

THX

2 个答案:

答案 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

它有效。