使用sfFilter更新DB与Doctrine [英] Using sfFilter to update DB with Doctrine

查看:183
本文介绍了使用sfFilter更新DB与Doctrine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个sfFilter来更新用户所在的当前模块:

  
class SessionFilter扩展sfFilter {
public function execute($ filterChain){
if($ this-> isFirstCall()){
$ user = $ this-> getContext() - > getUser() >的getId();
$ module = $ this-> getContext() - > getModuleName();
Doctrine :: getTable('ActiveSession') - > set($ user,$ module);
Doctrine :: getTable('ActiveSession') - > refresh();
}

$ filterChain-> execute();
}
}

当我查找数据库时,我发现该记录已将模块字段设置为默认,但是当我看到日志时,它显示:

  
UPDATE active_session SET module ='secretary'WHERE(sys_user_id ='2')

有谁知道如何修正这个行为?



编辑:我忘了放置和刷新方法的

  class ActiveSessionTable extends Doctrine_Table 
{
public function set($ userId,$ module){
$ q = $ this-> createQuery() - > update()
- > set('module','?',$ module)
- > where(sys_user_id =?,array($ userId)) - > execute();
}

public function refresh(){
$ time = time() - sfConfig :: get('app_session_keep')* 60;
$ this-> createQuery() - > delete() - > where('time<?',$ time) - > execute();
}
...
}

刷新方法应该用于其他方法,但用于测试我保持在那里。

解决方案

嗯...关闭这个。 p>

我可以完成我想要的唯一方法是检查模块是否为默认:

  class ActiveSessionTable extends Doctrine_Table 
{
public function set($ userId,$ module){
if($ module!='default'){
$ q = $ this-> createQuery() - > update()
- > set('module','?',$ module)
- > where(sys_user_id =? ,array($ userId)) - > execute();
}
}
...
}

真的不是一个快乐的答案,但找不到正确的答案。


I've created a sfFilter to update the current module where the user is at:


class SessionFilter extends sfFilter {
    public function execute($filterChain){
        if ($this->isFirstCall()){
            $user = $this->getContext()->getUser()->getId();
            $module = $this->getContext()->getModuleName();
            Doctrine::getTable('ActiveSession')->set($user, $module);
            Doctrine::getTable('ActiveSession')->refresh();
        }

        $filterChain->execute();
    }
}

When I look up into the db I found out that the record has set the field 'module' at 'default' but when I see the log it says:


UPDATE active_session SET module = 'secretary' WHERE (sys_user_id = '2')

Does anyone know how to fix this behaviour?

EDIT: I forgot to put the set and refresh method's

class ActiveSessionTable extends Doctrine_Table
{
    public function set($userId, $module){
        $q = $this->createQuery()->update()
            ->set('module','?', $module)
            ->where("sys_user_id = ?", array($userId))->execute();
    }

    public function refresh(){
        $time = time() - sfConfig::get('app_session_keep') * 60;
        $this->createQuery()->delete()->where('time < ?', $time)->execute();
    }
    ...
}

The refresh method should be used in other method but for testing I'm keeping it there.

解决方案

Well... to close this.

The only way I could accomplish what I wanted was to check if module was 'default':

class ActiveSessionTable extends Doctrine_Table
{
    public function set($userId, $module){
        if($module != 'default'){
            $q = $this->createQuery()->update()
               ->set('module','?', $module)
               ->where("sys_user_id = ?", array($userId))->execute();
        }
    }
   ...
}

really not a happy answer but couldn't find the right one.

这篇关于使用sfFilter更新DB与Doctrine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆