Answer the question
In order to leave comments, you need to log in
Silex - why don't Traits work?
I want to "get" the username of the user. In the doc they write:
Silex\Application\SecurityTrait adds the following shortcuts:
user: Returns the current user.
$user = $app->user();
Fatal error: Call to undefined method Silex\Application::user() in
use Application\UrlGeneratorTrait;, but, at that time, did not attach importance to the problem.
Answer the question
In order to leave comments, you need to log in
And so it works?
$token = $app['security']->getToken();
if (null !== $token) {
$user = $token->getUser();
}
class Application extends Silex\Application
{
use Silex\Application\TwigTrait;
}
$app = new Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/../views',
));
$app->get('/', function () use ($app) {
return $app->render('home.twig');
});
$app->run();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question