sfDoctrineGuard - 如何始终将 sfGuardProfile 加入 sfGuardUser

发布于 2024-08-30 19:20:54 字数 282 浏览 7 评论 0原文

我想让数据库随时查询sfGuardUserProfile,它会自动加入并与其相关的sfGuardUser结合。

如果我使用 Propel 1.2,我通常会重写 sfGuardUserProfilePeer 类的 doSelectStmt 方法来检查 Criteria 并根据需要进行修改修改 sfGuardUserProfile 类的 enchanted 方法。但我不确定如何在教义中做到这一点。

I want to make it so that anytime the db is queried for an sfGuardUserProfile it is autmoatically joined and hydrated with its related sfGuardUser.

If i was using Propel 1.2 i would normally override the doSelectStmt method of the sfGuardUserProfilePeer class to inspect the Criteria and modify it as necessary as well as modifying the hydrate method of the sfGuardUserProfile class. Im not sure how to go about doing this in Doctrine though.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-09-06 19:20:54

您可以使用事件监听器。在学说文档中阅读有关它们的更多信息:事件监听器

在 symfony 1.4 中 sfGuardUser 可以修改。默认情况下位于 lib/model/doctrine/sfDoctrineGuardPLugin/sfGuardUser.class.php 中。您可以添加以下 preDqlSelect() 方法来修改查询。请注意,它尚未经过测试。

class sfGuardUser extends PluginsfGuardUser
{
  public function preDqlSelect($event)
  {
    $params = $event->getParams();
    $query  = $event->getQuery();
    $alias  = $params['alias'] . '.Profile';
    if ((!$query->isSubquery() || ($query->isSubquery() && $query->contains(' ' .     $params['alias'] . ' '))) && !$query->contains($alias)) 
    {   
      $query->innerJoin($alias);
    }   
  }
}

要使其正常工作,您需要打开 DQL 回调。您可以在 ProjectConfiguration 类中执行此操作:

  class ProjectConfiguration extends sfProjectConfiguration
  {
    public function configureDoctrine(Doctrine_Manager $manager)
    {  
      $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
    }  
  }

You could use Event Listeners. Read more about them in the doctrine documentation: Event Listeners

In symfony 1.4 sfGuardUser can be modified. It's by default in lib/model/doctrine/sfDoctrineGuardPLugin/sfGuardUser.class.php. You can add following preDqlSelect() method to modify the query. Note that it's not tested.

class sfGuardUser extends PluginsfGuardUser
{
  public function preDqlSelect($event)
  {
    $params = $event->getParams();
    $query  = $event->getQuery();
    $alias  = $params['alias'] . '.Profile';
    if ((!$query->isSubquery() || ($query->isSubquery() && $query->contains(' ' .     $params['alias'] . ' '))) && !$query->contains($alias)) 
    {   
      $query->innerJoin($alias);
    }   
  }
}

To make it working you need to have DQL callbacks turned on. You can do it in your ProjectConfiguration class:

  class ProjectConfiguration extends sfProjectConfiguration
  {
    public function configureDoctrine(Doctrine_Manager $manager)
    {  
      $manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
    }  
  }
内心荒芜 2024-09-06 19:20:54

虽然我同意 Coronatus,但我认为您想要做的事情可以通过以下方式实现:

http: //www.symfony-project.org/plugins/sfGuardPlugin

请参阅“自定义 sfGuardUser 模型”。

基本上,配置文件需要称为“sf_guard_user_profile”并设置关系,然后您应该能够使用:

$this->getUser()->getGuardUser()->getProfile();

我认为某些配置文件目的需要正确的配置文件模型名称,但我可能是错的。

Although I agree with Coronatus, I think what you're looking to do can be achieved with:

http://www.symfony-project.org/plugins/sfGuardPlugin

See "Customize the sfGuardUser model".

Basically, the profile needs to be called "sf_guard_user_profile" and the relation set up, and then you should be able to use:

$this->getUser()->getGuardUser()->getProfile();

I think the right profile model name is needed for some config file purposes but I may be wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文