symfony的 - 管理模块过滤器访问的链接

问题描述:

我上的管理仪表板,这将是主要内容,在usingsfDoctrineGuardPlugin记录了当前用户的工作symfony的 - 管理模块过滤器访问的链接

我正在寻找做虽然是有联系在仪表板中,基本上是其他模块的过滤器。

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

例如,我想有以下为链接:

  • 名单新用户 - 此链接需要列出所有用户在过去30天
  • 列表供应商增加 - 这需要列出与2
  • 名单Manufactureres的GROUP_ID组中的所有用户 - 这需要列出是一组与3

我将如何去这样做GROUP_ID所有用户?

感谢

+0

所有这些不同的模块或一个,管理生成器或不是? – Dziamid 2011-04-15 21:26:03

+0

这些链接位于主管理页面,dashoboard上。这些链接需要筛选sfDoctrineGuard中的用户,sfGuardUser – 2011-04-18 14:47:31

我真的不认为你应该在你的情况下使用过滤器。过滤器是数据列表的临时条件。 这是一个更优雅的解决方案。我们将重新使用sfGuardUser索引操作的功能,并且“实时”设置它的table_method(基于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 
} 

就是这样。现在您可以添加指向您的仪表板的链接,如下所示:

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

P.S.此方法现在允许您在这些列表的顶部使用过滤器(出于其真实原因)。但是,您还必须调整适当的链接。

+0

非常好!今天我会看看这个,看看它是如何发展的。这几乎是我想要的,只是链接,显示基于他们的组的用户列表 – 2011-04-20 09:55:41

+0

好吧,我已经尝试与用户一起使用,并且工作得很好。但对其他模块使用相同的代码不起作用。例如,我在'orders'表上尝试过它,但它总是返回5条记录,而不是基于我的模型方法的特定记录。任何想法,为什么会是这种情况? – 2011-04-20 13:20:40

+0

似乎'$ this-> configuration-> setTableMethod($ table_method);'返回null,但我不知道为什么... – 2011-04-20 13:28:29

这里有一个问题:管理发生器记住所有过滤器的数据作为用户的属性(读作“其存储在会话信息”)。因此,如果您不关心过滤器的所有记忆数据,您可以创建一个接收GET参数的模块,将此参数设置为用户属性(sfUser-> setAttribute(...))覆盖所需模块的过滤器数据,并重定向到模块。

或者

您可以使用GET参数,将它们添加到过滤器覆盖的PARAMS模块URL(example.com/users?filter[group_id]=123)。在这种情况下,您应该在每个需要的模块中处理这些信息。

+0

您能否给我提供一个例子:users?filter [group_id] = 1不返回任何东西 – 2011-04-18 14:46:06