如何解决Symfony管理员生成器,链接到过滤结果
| 我有以下模型的管理员生成器:#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>
谢谢
解决方法
本讲座回答您的问题(幻灯片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
,则必须在上面的函数(第5行)中写入authorId
。如果架构中有“ 7”,则必须在函数中编写“ 7”。另外,模块名称总是带小写的下划线(例如:schema : MyBooks -> module name: my_books
)。
在您的generator.yml中
list:
object_actions:
_edit: ~
_delete: ~
viewPhones: { label: View books,action: viewBooks }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。