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

Php 将参数传递给自定义控制台命令symfony2,php,symfony,Php,Symfony,为了在控制台命令中获取当前用户,我想将用户id传递给我的自定义控制台命令 1.有没有办法实现这一点 2.或者有没有其他好的方法来获取当前用户 Thx要通过命令行选择某个用户,您可以查看著名的FOSUserBundle: protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); // inte

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

1.有没有办法实现这一点

2.或者有没有其他好的方法来获取当前用户


Thx

要通过命令行选择某个用户,您可以查看著名的
FOSUserBundle

protected function execute(InputInterface $input, OutputInterface $output)
{
    $username = $input->getArgument('username');
    // interact with the username.

调用像
php app/console这样的命令:command username

非常感谢@RoyalBg。我通过添加一个论点来解决这个问题

->addArgument('user_id', InputArgument::OPTIONAL, 'The id of the current user')
然后我运行命令

php app/console ssss $userid

它有效。

当前用户
指的是什么?UNIX用户?或者您想提供一个
id
,然后Symfony2在其数据库中查找用户?您是说cli?使用argv阵列而不是Unix用户。只有登录我的页面的用户@比亚夫·费迪,你能详细解释一下吗?非常感谢@royalbg$argv数组包含通过控制台传递的参数。例如:
php path/to/file/file.php bla
$argv[1]将是“bla”。因此,例如,如果您有
从id=$argv[1]
的用户中选择用户名,并调用
php path/to/file/file.php 100
,您将在脚本中使用
从id=100的用户中选择用户名