Closed cipherchien closed 9 years ago
What type of authentication are you using?
I found the solution.
class AnnotationConfigurationPass implements CompilerPassInterface
{
......
public function process(ContainerBuilder $container)
{
......
foreach ($files as $class) {
.......
if ($class->implementsInterface('Symfony\Component\DependencyInjection\ContainerAwareInterface')) {
$container->setDefinition($serviceId, $definition)
->addMethodCall('setContainer', [new Reference('service_container')]);
} else {
$container->setDefinition($serviceId, $definition);
}
......
then I rewrite my Register code:
use Voryx\ThruwayBundle\Annotation\Register;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Register implements ContainerAwareInterface
{
protected $container;
public function setContainer(ContainerInterface $container = null) {
$this->container = $container;
// $user = $this->container->get('security.token_storage')->getToken()->getUser(); // It's not work and stuck here
$managerUser = $this->container->get('fos_user.user_manager');
$user = $managerUser->findUserBy(array('username'=>'ABC')); // it's work
$logger = $this->container->get('oz_base.logger');
$logger->info($user->getUsername());
}
/**
* @Register("user.line.open")
*/
public function userLineOpenAction($userID, $threadID)
{
$logger = $this->container->get('oz_base.logger');
$logger->info($userID);
$logger->info($threadID);
return "done";
I haven't implement authentication yet. If I use authentication, the solution will make different?
Hi,
I try to use a register controller, but I got some problems. Here is my config setting and code:
and the controller:
the client side code:
If the action is like this, the register can work and the client can response the response data.
What's error with my code? And how to get container service in Register action?
Thank you.