1

我正在使用2.2FOSUserBundle项目。我正在尝试扩展该类并向其添加一个新方法,如下所示:PropelSymfonyUser

namespace Acme\UserBundle\Model;

use FOS\UserBundle\Propel\User as BaseUser;

class User extends BaseUser
{
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    public function hasPermission($topic) {
        // TODO check if $topic has permission
        return TRUE;
    }
}

问题是在控制器中调用时$this->getUser(),返回的对象的类是FOS\UserBundle\Propel\User,所以hasPermission()是未定义的。

我尝试在自定义类的构造函数中抛出异常,它似乎在注册新用户时使用。但我想它没有保存为Acme\UserBundle\Model\User.

我在另一个项目中尝试过这个,Doctrine它在调用时返回了正确的类$this->getUser()。难道我做错了什么?我如何使它与 Propel 一起工作?

配置.yml:

fos_user:
    db_driver: propel
    firewall_name: main
    user_class: Acme\UserBundle\Model\User

安全性.yml:

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }
4

1 回答 1

0

我安装了GlorpenPropelBundle,在 config.yml 中添加了几行。

配置.yml

propel:
    classname: Glorpen\Propel\PropelBundle\Connection\EventPropelPDO
    build_properties:
        propel.behavior.event.class:    'vendor.glorpen.propel-bundle.Glorpen.Propel.PropelBundle.Behaviors.EventBehavior'
        propel.behavior.extend.class:   'vendor.glorpen.propel-bundle.Glorpen.Propel.PropelBundle.Behaviors.ExtendBehavior'
        propel.behavior.default:        "event, extend"

glorpen_propel:
    extended_models:
        FOS\UserBundle\Propel\User: Acme\UserBundle\Model\User

$this->getUser()现在返回Acme\UserBundle\Model\User

于 2013-05-20T12:54:56.890 回答