Symfony管理生成器,链接到过滤结果

Ben*_*ier 5 symfony1 filter admin-generator

我有一个管理生成器用于以下模型:

#schema.yml
Author:
  columns:
    name: { type: string(255), notnull: true }

Book:
  columns:
    authorId: { type: integer, notnull: true }
    title: { type: string(512), notnull: true }
    content: { type: string(512), notnull: true }
  relations:
    Author: { onDelete: CASCADE, local: authorId, foreign: id, foreignAlias: Books}
Run Code Online (Sandbox Code Playgroud)

我已经创建了2页,每页都对应一页

php symfony doctrine:generate-admin backend Author
php symfony doctrine:generate-admin backend Book
Run Code Online (Sandbox Code Playgroud)

现在我想在作者视图中找到他的书的链接.最好的方法是什么?我的尝试是一个预先选择过滤器的自定义链接,但我不知道该怎么做.

#generator.yml for Author
# ...
    config:
      actions: ~
      fields:
      list:
        display: [id, name, _booksLink]
      filter:  ~
      form:    ~
      edit:    ~
      new:     ~
Run Code Online (Sandbox Code Playgroud)

<!-- modules/author/templates/_booksLink.php -->
<a href="<?= link_to('book?author_id='.$author->getId()) ?>"><!-- how to select filter? -->
  See <?= $author->getName() ?> books
</a>
Run Code Online (Sandbox Code Playgroud)

谢谢

Are*_*end 5

本讲座回答了您的问题(幻灯片39和40):http: //www.slideshare.net/jcleveley/working-with-the-admin-generator

在你的actions.class php add:


class AuthorActions extends AutoAuthorActions
{
  public function executeViewBooks($request) { 
    $this->getUser()->setAttribute( 'book.filters',   
    array('authorId' => $request->getParameter('id')), 'admin_module' ); 
    $this->redirect($this->generateUrl('book')); 
  }
}
Run Code Online (Sandbox Code Playgroud)

关于这种情况的注意事项:字段名称与模式中定义的大小写相匹配.例如:如果你authorId在模式中,你必须写authorId上面的函数(第5行).如果您author_id在架构中,则必须author_id在函数中写入.此外,模块名称始终为小写,带下划线(例如:) schema : MyBooks -> module name: my_books.

在您的generator.yml中


list: 
  object_actions:
    _edit: ~
    _delete: ~
    viewPhones: { label: View books, action: viewBooks }