Symfony generator generator, link to filter result

I have an admin generator for the following model:

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

I looked at 2 pages corresponding to each table

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

Now I want the author to have a link to his books. What is the best way to do this? My attempt is a custom link that pre-selects filters, but I don't know how to do this.

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

and

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

thank

+5
source share
1 answer

This lecture answers your question (slide 39 and 40): http://www.slideshare.net/jcleveley/working-with-the-admin-generator

in your action.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')); 
  }
}

: , . : authorId, authorId ( 5). author_id, author_id . , (: schema : MyBooks -> module name: my_books).

.yml


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

All Articles