[英]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.