symfony 过滤器的附加条件

发布于 2024-12-07 09:39:52 字数 1242 浏览 1 评论 0原文

我正在开发一个 symfony 项目来管理数据库。首先我解释一下它是如何工作的:

在数据库中,所有元素都与唯一的元素“场景”相关联。当用户访问应用程序时,选择他想要查看的场景(它将其保存在用户参数中)。因此,在列出元素时,应用程序应该只列出与用户选择的场景相关的元素。

*注意:所有元素在表定义中都有一个场景属性。

所以我的问题来了:

我使用 sfPropelPager 类的帮助开发了一个元素实体列表来进行分页。还添加了一些过滤器来在列表中搜索,为此我使用了 symfony 提供的过滤系统(FormFilter.class.php 等)。

现在我希望列表不显示用户选择的其他场景中的元素。

我该如何向过滤器类给出的条件添加附加条件? 或者你会如何解决这个问题?

这是我的操作代码:

  public function executeUnidadfilter(sfWebRequest $request){
    $this->filter = new BaUnidadorganizativaTblFormFilter();
    $c = $this->filter->getCriteria();
    $this->filter->bind($request->getParameter($this->filter->getName()));
    if($this->filter->isValid()){
      $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
      echo $this->getUser()->getEscenario();
      $this->pager->setCriteria($c);
      $this->pager->init();
   }else{
      $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
      $this->pager->init();
   }
   $this->setTemplate('Unidadlist');
 }

*注意:下面提到的“场景”是代码中的 Escenario

非常感谢您的宝贵时间

i'm working on a symfony project to manage a database. First i explain how it works:

In the database, all elements are associated to an unique element 'scene'. When a user accesses the application, chooses what scene he wants to see (it saves that in a user parameter). So when listing elements, the application should only list elements associated with the scene selected by the user.

*Note: all elements have an scene attribute in the table definition.

So my problem comes here:

I developed a listing of an element entities using the help of a sfPropelPager class to paginate. Also added some filters to search in the list, and for that i used the filter system provided by symfony (<element>FormFilter.class.php and stuff).

Now i want the list to not show elements from other scenes than the selected by the user.

How can i do to add additional criteria to the criteria given by the filter class?
or How would you solve the problem?

here is my action code:

  public function executeUnidadfilter(sfWebRequest $request){
    $this->filter = new BaUnidadorganizativaTblFormFilter();
    $c = $this->filter->getCriteria();
    $this->filter->bind($request->getParameter($this->filter->getName()));
    if($this->filter->isValid()){
      $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
      echo $this->getUser()->getEscenario();
      $this->pager->setCriteria($c);
      $this->pager->init();
   }else{
      $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
      $this->pager->init();
   }
   $this->setTemplate('Unidadlist');
 }

*Note: 'scene' mentioned below is Escenario in the code

thank you very much for your time

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

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

发布评论

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

评论(1

奶气 2024-12-14 09:39:52

我解决了这个问题。问题是我在填充过滤器之前将 formfilter 生成的条件分配给了我的条件 var 。这就是错误的原因。

结果代码是这样的:

  public function executeUnidadfilter(sfWebRequest $request){
    $this->filter = new BaUnidadorganizativaTblFormFilter();
    $this->filter->bind($request->getParameter($this->filter->getName()));
    if($this->filter->isValid()){
        $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
        $esc = $this->getUser()->getEscenario();
        $c = new Criteria();
        $c = $this->filter->getCriteria();
        $c->addAnd('codigo_escenario',$esc);
        $this->pager->setCriteria($c);
        $this->pager->init();
    }else{
        $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
        $this->pager->setCriteria($this->filter->getCriteria());
        $this->pager->init();
    }
    $this->message=null;
    $this->messageType=null;
    $this->setTemplate('Unidadlist');
 }

I solved the problem. The trouble was that i assigned the formfilter generated criteria to my criteria var Before the filter was filled. That's why of the error.

The resulting code is that:

  public function executeUnidadfilter(sfWebRequest $request){
    $this->filter = new BaUnidadorganizativaTblFormFilter();
    $this->filter->bind($request->getParameter($this->filter->getName()));
    if($this->filter->isValid()){
        $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
        $esc = $this->getUser()->getEscenario();
        $c = new Criteria();
        $c = $this->filter->getCriteria();
        $c->addAnd('codigo_escenario',$esc);
        $this->pager->setCriteria($c);
        $this->pager->init();
    }else{
        $this->pager = new sfPropelPager('BaUnidadorganizativaTbl',$this->sfPropelPagerLines);
        $this->pager->setCriteria($this->filter->getCriteria());
        $this->pager->init();
    }
    $this->message=null;
    $this->messageType=null;
    $this->setTemplate('Unidadlist');
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文