奏鸣曲管理员搜索功能 [英] Sonata Admin search feature
问题描述
我最近更新了我的 symfony2 项目供应商.因此我得到了最新的 Sonata Admin Bundle 版本(从 2.2.5 更新到 2.2.6).
I recently updated my symfony2 project vendors. Thus I got latest Sonata Admin Bundle version (updated from 2.2.5 to 2.2.6).
我看到此版本中有一个新的搜索功能,但我无法使用它.我无法弄清楚我做错了什么.快把我逼疯了.
I saw there is a new search feature in this release but I can't get it work. I can't figure out what I'm doing wrong. Drives me crazy.
这是我的 composer.json 要求:
Here is my composer.json require :
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"jms/security-extra-bundle": "1.5.*",
"doctrine/data-fixtures": "1.0.*",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/migrations": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
"stof/doctrine-extensions-bundle": "1.1.*",
"friendsofsymfony/user-bundle" : "1.3.*",
"knplabs/knp-menu-bundle": "1.1.*",
"knplabs/gaufrette": "dev-master",
"knplabs/knp-paginator-bundle": "2.3.*",
"sonata-project/easy-extends-bundle" : "2.1.*",
"sonata-project/cache-bundle": "2.1.*",
"sonata-project/jquery-bundle": "1.8.*",
"sonata-project/exporter": "1.3.*",
"sonata-project/block-bundle": "2.2.*",
"sonata-project/user-bundle": "2.2.*@dev",
"sonata-project/admin-bundle": "2.2.*",
"sonata-project/doctrine-orm-admin-bundle": "2.2.*",
"sonata-project/doctrine-extensions": "1.0.0",
"sonata-project/google-authenticator": "1.0.0",
"sonata-project/intl-bundle": "2.2.*@dev",
"sonata-project/media-bundle": "2.2.*",
"sonata-project/notification-bundle": "2.2.*",
"sonata-project/formatter-bundle": "2.3.*",
"hwi/oauth-bundle": "0.3.*@dev",
"elao/web-profiler-extra-bundle": "2.3.*@dev",
"liip/functional-test-bundle": "dev-master",
"guzzle/guzzle": "v3.4.1",
"jms/serializer-bundle": "0.12.*@dev",
"friendsofsymfony/rest-bundle": "0.12.0",
"friendsofsymfony/comment-bundle": "2.0.*@dev",
"whiteoctober/breadcrumbs-bundle": "dev-master",
"igorw/file-serve-bundle": "1.0.*",
"zendframework/zendpdf": "2.0.*"
},
更新后,我的搜索功能抱怨一个不存在的块:
Right after the update I had the search feature complaining about a non existing block :
在渲染模板期间抛出异常(The块类型 Sonata.admin.block.search_result 不存在") 中SonataAdminBundle:Core:search.html.twig 在第 48 行
An exception has been thrown during the rendering of a template ("The block type sonata.admin.block.search_result does not exist") in SonataAdminBundle:Core:search.html.twig at line 48
我通过在我的 config.yml
中声明块来纠正这个:
I corrected this one by declaring the block in my config.yml
:
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
但是现在,它抱怨请求未设置:
But now, it is complaining about request not set :
在渲染模板期间抛出异常(The请求对象尚未设置")中SonataAdminBundle:Core:search.html.twig 在第 48 行
An exception has been thrown during the rendering of a template ("The Request object has not been set") in SonataAdminBundle:Core:search.html.twig at line 48
我真的不明白我在这里错过了什么.任何帮助将不胜感激.
I really don't understand what I'm missing here. Any help would be much appreciated.
推荐答案
我遇到了同样的错误.可能是因为您在管理员中使用请求.
I got the same error. It's probably because you are using the Request in an Admin.
$this->getRequest()->get('context', 'default')
搜索未设置请求,如果您尝试获取请求,管理员会触发异常.
The search does not set the request and the Admin triggers an exception if you are trying to get the request.
在我的管理员中,我使用一个函数来访问请求参数并避免异常.
In my Admin, I am using a function to access the request parameter and avoid an exception.
public function getRequestParameterOrNull( $key, $default = null ){
try{
return $this->getRequest()->get($key, $default);
}catch(\Exception $e){
return null;
}
}
这篇关于奏鸣曲管理员搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!