symfony - 管理模块过滤器可作为链接访问 [英] symfony - admin module filters accessible as links

查看:24
本文介绍了symfony - 管理模块过滤器可作为链接访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个管理仪表板,它将主要基于使用sfDoctrineGuardPlugin登录的当前用户

I am working on an admin dashboard, which will be mainly based on the current user that is logged in usingsfDoctrineGuardPlugin

不过,我想要做的是在仪表板中有链接,这基本上是其他模块的过滤器.

What I'm looking to do though, is to have links in the dashboard, that are basically filters to other modules.

问题是,我不知道该怎么做.

The problem is, I'm not sure how I'd do that.

例如,我希望将以下内容作为链接:

For example, I'd like to have the following as links:

  • 列出新用户 - 此链接需要列出过去 30 天内添加的所有用户
  • 列出供应商 - 这需要列出属于 group_id 为 2 的组的所有用户
  • 列出制造商 - 这需要列出 group_id 为 3 的组中的所有用户

我该怎么做?

谢谢

推荐答案

我真的不认为你应该在你的情况下使用过滤器.过滤器是数据列表的临时条件.这是一个更优雅的解决方案.我们将重用 sfGuardUser 索引操作的功能,并即时"设置其 table_method(基于 url).

I truly don't think you should use filters in your case. Filters are temporary conditions to your data list. Here's a more elegant solution. We will reuse the functionality of sfGuardUser index action, and set its table_method "on the fly" (based on url).

//exetent the configuration class to override getTable method
class sfGuardUserGeneratorConfiguration extends BaseSfGuardUserGeneratorConfiguration
{
  protected $tableMethod = null;

  public function setTableMethod($name)
  {
    $this->tableMethod = $name;
  }

  public function getTableMethod()
  {
    return null !== $this->tableMethod ? $this->tableMethod : parent::getTableMethod();
  }
}

//now we need to set the tableMethod based on a route param (list):
class sfGuardUserActions extends autoSfGuardUserActions
{
  public function executeIndex(sfWebRequest $request)
  {
    //create a mapping between an url and table method
    $map = array(
      'clients' => 'getClientsList',
      'suppliers' => 'getSuppliersList',
      'manufacturers' => 'getManufacturersList',
    );
    $list = $request->getParameter('list');
    $table_method = isset($map[$list]) ? $map[$list] : null;
    $this->configuration->setTableMethod($table_method);
    parent::executeIndex($request);
  }
}

//create a custom url for your lists:
sf_guard_user_list:
  url:   /guard/users/:list
  param: { module: sfGuardUser, action: index}
  requirements:
    list: clients|suppliers|manufacturers

//and model methods for each of your lists:
class sfGuardUserTable extends PluginsfGuardUserTable
{
  /**
   * List of clients query
   *
   */
  public function getClientsList()
  {
    $q = $this->createQuery('u')
      ->leftJoin('u.Groups g')
      ->where('g.name = ?', 'client');

    return $q;
  }
  //and others
}

就是这样.现在,您可以像这样向仪表板添加链接:

That's it. Now you can add links to your dashboard like this:

<?php echo link_to('Clients', 'sf_guard_user_list', array('list'=>'clients')) ?>

附言这种方法现在允许您在这些列表的顶部使用过滤器(出于真正的原因).但是,您还必须调整相应的链接.

P.S. this approach now allows you to use filters (for their true reasons) on top of these lists. But, you will also have to adjust the appropriate links.

这篇关于symfony - 管理模块过滤器可作为链接访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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