와 Symfony2에서 내가 그들의 URL과 해시를 사용자에게 자동 로그인 내 사이트에있는... UsernamePasswordToken
를 세션을 시작할 수 없습니다 사용자의 액션은 매우 간단하고, 단지 내가 (일부 확인 후) 할 생각이다 (나는 ... 항상 작동 할 때) 작동 어떤 경우에는이와
$token = new UsernamePasswordToken($user, $user->getPassword(), 'secured_area', $user->getRoles());
$this->get('security.context')->setToken($token);
하지만, 일부의 경우 작동하지 않습니다 ...이 경우의 로그는 다음과 같습니다 :
[2014-10-30 15:47:25] request.INFO: Matched route "_my_route" (parameters: "_controller": "MyController", "url": "my-url", "hash": "2f5fccc7b5fc2d41bbc3e1e469655f24f540e383", "_route": "_my_route") [] []
[2014-10-30 15:47:25] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2014-10-30 15:47:25] security.DEBUG: Write SecurityContext in the session [] []
[2014-10-30 15:47:25] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Failed to start the session because headers have already been sent by "/route/app/bootstrap.php.cache" at line 1365." at /route/app/cache/prod/classes.php line 119 {"exception":"[object] (RuntimeException: Failed to start the session because headers have already been sent by \"/route/app/bootstrap.php.cache\" at line 1365. at /route/app/cache/prod/classes.php:119)"} []
[2014-10-30 15:47:25] security.DEBUG: Write SecurityContext in the session [] []
헤더가 이미 전송 된 이유는 무엇입니까? 왜 어떤 경우에만? 누군가가 자주 일어나는 경우를 알고 있습니까? 이 전에 인쇄에는 문자, security.yml에 방화벽을 변경하지 있는지 확인 디스크 파일에 세션을 넣어 ... 나는 모두가 OK라고 생각
:
나는 많은 것들을 시도했다. 내 사용자 엔티티 :class MyUser implements UserInterface, \Serializable
{
...
/**
* Serializes the user.
*
* The serialized data have to contain the fields used byt the equals method.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->password,
$this->email
));
}
/**
* Unserializes the user.
*
* @param string $serialized The serialized string
*
* @return void
*/
public function unserialize($serialized)
{
list(
$this->id,
$this->password,
$this->email
) = unserialize($serialized);
}
...
Security.yml
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
MyProject\PublicBundle\Entity\MyUser:
algorithm: sha1
iterations: 1
encode_as_base64: false
role_hierarchy:
ROLE_USER: ROLE_PENDING
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
entity: { class: MyProject\PublicBundle\Entity\MyUser, property: email }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
failure_path: /login
username_parameter: email
password_parameter: password
default_target_path: /login-redirect
logout:
path: /logout
target:/
remember_me:
key: "aSecretKey"
lifetime: 321408000
path: /
domain: %domain%
config.yml (세션 부분은 첫번째 오류 후에 추가 된)이 가능성과 관련이있다
framework:
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/sessions"
fragments: ~
http_method_override: true
당신은 또한 config.yml에서 섹션 프레임 워크를 제공 할 수 있습니다 :
당신은 같은 서비스를 사용하고 있습니까? – s7anley
1365 줄의 "/route/app/bootstrap.php.cache"에있는 내용입니다. " – Chausser
config.yml의 프레임 워크로 업데이트했습니다. sendContent 함수가 에코입니까? public function sendContent() { echo $ this- > 콘텐츠; // 1365 return $ this; } 감사합니다. – aaubets