5

次のモデルの管理ジェネレーターがあります。

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

ありがとう

4

1 に答える 1

5

この講義はあなたの質問に答えます(スライド39と40): http: //www.slideshare.net/jcleveley/working-with-the-admin-generator

あなたのactions.classphpに追加:


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 -> module name: my_books

あなたのgenerator.ymlで


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

于 2011-06-01T12:33:31.827 に答える