duanji8615 2012-10-16 11:04
浏览 6
已采纳

如何检查模板中是否已应用过滤器?

I'm working on an admin-generator module. I'd like to hide the item-list until the user has used the filters. So I'd like to check, if the filter-form has been sent.

Is there any var I can check for this in the indexSuccess.php Template?

  • 写回答

1条回答 默认 最新

  • doubei8541 2012-10-16 12:11
    关注

    Filters are stored inside the session when the user submit them.

    So, in your template, you can access defined filter by calling the session. If you don't have defaults filter, it will return an empty array (might be sfOutputEscaperArrayDecorator if you use output protection).

    If you module name is car for example, you can get filters inside your template using:

    $filters = $sf_user->getAttribute('car.filters', null, 'admin_module');
    

    And if you use output protection, you can do:

    $filters = sfOutputEscaper::unescape($sf_user->getAttribute('car.filters', null, 'admin_module'));
    

    If you do not have filters, you will get something like this with a var_dump (with the first solution):

    object(sfOutputEscaperArrayDecorator)[181]
      private 'count' => int 0
      protected 'value' => 
        array
          empty
      protected 'escapingMethod' => string 'esc_specialchars' (length=16)
    

    And with the second:

    array
      empty
    

    For example, if you have some filters define, you will get :

    array
      'model' => 
        array
          'text' => string 'test' (length=4)
      'updated_at' => 
        array
          'from' => null
          'to' => null
      'created_at' => 
        array
          'from' => null
          'to' => null
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line