0

I am trying to run a command from a controller but it does not work. This is my code:

            $email = $request->get('email');
            if (empty($email))
                $email = $request->get('nombres');
            if (empty($password))
                $password = '123456';                
            $application = new Application($this->container->get('kernel'));
            $application->setAutoExit(false);                 
            $input = new ArrayInput(array(
                "command" => "fos:user:create",
                "username" => $username,
                "email" => $email,
                "password" => $password));

            $output = new ConsoleOutput();
            $retval = $application->run($input, $output);

            var_dump(stream_get_contents($output->getStream()));
            die();

Simply it does nothing, #retval is 1 and the $output var is empty.

Any help will be appreciated Thanks

Jaime

1 Answer 1

1

Basically you should not use command in controllers. Console command and Controller are two different delivery layers.

Please use services (so you can use it in controllers and in commands) for fos:user:create you can use something like that:

 $manipulator = $this->container->get('fos_user.util.user_manipulator');
 $manipulator->create($username, $password, $email, $active = true, $superadmin = false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.