Search code examples
symfony1symfony-1.4

symfony: using generator.yml,is there any solution to hide the fields from users only and show it for Admin


I build a beckend for my project using "admin generator" of symfony 1.4,so I can access such as an Admin and other members like a user(role)...

I hope to hide passwords in members list in backend,then when I login like Admin (is_super_admin =1 in DB: sf_guard_user) so I can see passwords but when someone login like a user so he can't see the same field (is_super_admin =0 in DB:sf_guard_user).

I'm asking if they are any solution to hide field using role and generator.yml or any other solution?


Solution

  • Yes you can do it like this:

    # generator.yml
    generator:
      class: fdDoctrineGenerator
      param:
        model_class:           sfGuardUser
        theme:                 admin
        non_verbose_templates: true
        with_show:             false
        singular:              ~
        plural:                ~
        route_prefix:          user
        with_doctrine_route:   true
        actions_base_class:    sfActions
    
        config:
          actions: ~
          fields:
            password:
              credentials: [super_admin]
          list:
            display: [=username, password]
          filter   ~
          form:    ~
          edit:    ~
          new:     ~
    

    If you have admins with is_super_admin == true than you can use any credentials which is not assigned to any users.