【问题标题】:Symfony admin generator, link to filtered resultSymfony 管理生成器,链接到过滤结果
【发布时间】:2011-09-05 16:10:38
【问题描述】:

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

#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}

我已经生成了2页,每个表都对应

php symfony doctrine:generate-admin backend Author
php symfony doctrine:generate-admin backend Book

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

#generator.yml for Author
# ...
    config:
      actions: ~
      fields:
      list:
        display: [id, name, _booksLink]
      filter:  ~
      form:    ~
      edit:    ~
      new:     ~

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

谢谢

【问题讨论】:

    标签: symfony1 filter admin-generator


    【解决方案1】:

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

    在你的actions.class php中添加:

    
    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')); 
      }
    }
    

    关于大小写的注意事项:字段名称与架构中定义的大小写匹配。例如:如果架构中有authorId,则必须在上面的函数中写authorId(第5行)。如果架构中有author_id,则必须在函数中写入author_id。此外,模块名称始终为小写并带有下划线(例如:schema : MyBooks -&gt; module name: my_books)。

    在您的 generator.yml 中

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

    【讨论】:

    • 太好了,感谢修复它,我总是按照惯例使用下划线表示法,我忘了还有其他可能的表示法,
    • 好主意,到目前为止,我一直在使用更老套的方法来实现这一目标。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    相关资源
    最近更新 更多