Reputation: 481
In order to get the current user in console command, I want to pass the user_id to my custom console command.
1.Is there a way to implement this?
2.Or are there any other good ways to get the current user?
Thx
Upvotes: 0
Views: 1427
Reputation: 481
Thank to @RoyalBg very much. I solve the problem by adding a argument.
->addArgument('user_id', InputArgument::OPTIONAL, 'The id of the current user')
then I run the command
php app/console ssss $userid
it works.
Upvotes: 0
Reputation: 6410
For selecting a certain user over the command line you can take a look at the command of the famous FOSUserBundle
:
protected function execute(InputInterface $input, OutputInterface $output)
{
$username = $input->getArgument('username');
// interact with the username.
Call the command like php app/console your:command username
.
Upvotes: 1