开发者

User relationships are corrupting my sessions in Symfony2

My users have a number of relationships setup in Doctrine but one in particular seems to be causing me a lot of problems, each user can have a number of memberships and each membership has a membership type.

For some reason however when I load those memberships it seems to be nuking my session, I login and get presented with a "Your Account" page as I should do but if I refresh the page I get sent back to the login screen. My sessions are stored in the database so I've been checking them to see what happens and this is what I'm seeing:

  1. Session starts off empty
  2. I login but make sure I get redirected to a page that doesn't load memberships
  3. Session now contains user object and all info about relationships
  4. I visit "Your Account" which loads memberships, they get displayed correctly.
  5. Session has been nuked and is now as it was in step 1
  6. I refresh the page and get sent back to the login page

I've defined my own user provider and I noticed if I set the membership type on each membership to null in refreshUser it starts working so I'm guessing the session is having trouble with that relationship.

I'm really struggling to find a solution to this so any help would be really appreciated.

EDIT: Been doing some more experimenting and found if I switch to file sessions everything starts working so it must be related to storing sessions in the database. I made the switch using the guide in the Symfony Cookbook. For reference here are the relevant bits from my config.yml:

framework:
    session: 
        default_locale: %locale%
        auto_start:     true
        storage_id:   session.st开发者_运维问答orage.pdo

 parameters:
    pdo.db_options:
        db_table:       session
        db_id_col:      session_id
        db_data_col:    session_value
        db_time_col:    session_time

 session.storage.pdo:
    class:     Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage
    arguments: [@pdo, %session.storage.options%, %pdo.db_options%]
 pdo:
    class: PDO
    arguments:
        dsn:      "mysql:dbname=%database_name%;host=%database_host%"
        user:     %database_user%
        password: %database_password%

Everything else about them seems fine so maybe it's a bug in PdoSessionStorage


It might be in you equals method that is too strict. if you do $user === $otherUser; and the object have changed (the relation isnt a collection with proxies anymore) it would return false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜