Filter content in Symfony 1.2.x admin generator?

2019-06-11 13:33发布

问题:

I have a Symfony 1.2.7 application where 3 different sites coexist in the same database. All content has a foreign key, 'site_id', that says which site it belongs to.

In my generated admin interface I want to be able to show content from the currently selected site (actually set using a filter class, based on the domain used to access the admin interface).

An example:

Using 'www.domain.com/admin/', the user has access to content belonging to the 'domain.com' domain (with site_id=1) and this site only.

Any ideas on how to achieve this?

Thanks in advance

回答1:

you can use table_method option in the generator.yml of your Content module:

        config:
...
          list:
            table_method: getSiteContent
...

then write a method in your Content_Table class that modifies the query object:

public function getSiteContent(Doctrine_Query $q) {
        $q->andWhere( some where condition with site_id );
        return $q;
}