내 확장 번들에 현재 로그인 된 사용자를 가져 오려고했습니다.
$user = $this->get("security.context")->getToken()->getUser();
&
$user = $this->get("security.context")->getToken()->getUser();
같은 결과를 반환합니다. string(5) "anon."
$user = $this->getUser(); return `NULL`
아래는 내가 시도한 코드입니다.
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');
}
}
내 코드에 무슨 문제가 있니, Pls는 Guyz를 도와주세요 ........
보안에서 여러 방화벽 (관리자 측 및 전면 사용자 측)을 사용하는 솔루션이 있으며 시스템은 서로 다른 방화벽간에 컨텍스트를 공유하지 않습니다.
http://symfony.com/doc/current/reference/configuration/security.html#firewall-context
# app/config/security.yml
security:
# ...
firewalls:
admin:
# ...
context: my_context
main:
# ...
context: my_context
위의 코드는 내 문제를 해결했습니다. 지원해 주셔서 감사합니다 ....
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다