I tried to get current logged user in my extended bundle
$user = $this->get("security.context")->getToken()->getUser();
&
$user = $this->get("security.context")->getToken()->getUser();
returns same result something like string(5) "anon."
$user = $this->getUser(); return `NULL`
Below is the code I tried
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\User;
class ClientController extends Controller
{
public function clientDashboardAction()
{
$user = $this->get("security.context")->getToken()->getUser();
echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user);
echo '</pre>';
// returns string(5) "anon."
$user = $this->getUser();
echo '<pre>';
\Doctrine\Common\Util\Debug::dump($user);
echo '</pre>';
//returns NULL
return $this->render('AppBundle:Client:clientDashboard.html.twig');
}
}
What's wrong with my code , Pls help me Guyz ........