我试图在我的symfony2.1项目中使用以下两个捆绑包:
- sonata管理捆绑包
- 精心设计的引导程序包
我的问题是,这两个捆绑包同时使用knp菜单捆绑包。但是sonata需要knp菜单捆绑包的1.1.x-dev以及精心设计的引导程序捆绑包开发大师。
使用以下composer设置,我得到以下错误。Composer.json:
"sonata-project/admin-bundle": "dev-master", "sonata-project/doctrine-orm-admin-bundle": "dev-master", "sonata-project/intl-bundle": "dev-master", "sonata-project/cache-bundle": "dev-master", "knplabs/knp-menu-bundle": "1.1.x-dev", "braincrafted/bootstrap-bundle": "dev-develop"
错误:在vendor/braincraft/bootstrap bundle/Braincraft/bootstrap bundle/Voter/RequestVoter 中找不到Knp\Menu\Matcher\Voter\VoterInterface
我知道Matcher在早期的knp菜单捆绑包版本中并不存在。但如果我将knp菜单捆绑包版本更改为:
"knplabs/knp菜单捆绑包":"dev-master",
无法安装sonata管理捆绑包。如果我执行命令"composer.phar update",会发生以下错误
Problem 1
- sonata-project/admin-bundle dev-master requires knplabs/knp-menu-bundle >=1.1.0,<2.0.x-dev -> satisfiable by knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle v1.1.0.
- sonata-project/admin-bundle dev-master requires knplabs/knp-menu-bundle >=1.1.0,<2.0.x-dev -> satisfiable by knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle 1.1.x-dev, knplabs/knp-menu-bundle v1.1.0.
- Can only install one of: knplabs/knp-menu-bundle dev-master, knplabs/knp-menu-bundle 1.1.x-dev.
- Can only install one of: knplabs/knp-menu-bundle dev-master, knplabs/knp-menu-bundle 1.1.x-dev.
- Can only install one of: knplabs/knp-menu-bundle v1.1.0, knplabs/knp-menu-bundle dev-master.
- Installation request for knplabs/knp-menu-bundle dev-master -> satisfiable by knplabs/knp-menu-bundle dev-master.
- Installation request for sonata-project/admin-bundle dev-master -> satisfiable by sonata-project/admin-bundle dev-master.
有人知道我如何使用这两个捆绑包吗?或者没有办法吗?谢谢你的帮助。
编辑composer.json并参考knp菜单包修改行,如下所示:"knplabs/knp菜单捆绑包":"1.1.x-dev",
它需要一个版本>=1.1.0,<2.0.x-dev,在错误的第一行中说明。
这对我有用。
使用Composer不能同时使用两个bundle。实际上你应该在https://github.com/braincrafted/bootstrap-bundle并解释情况。他们应该更新项目的composer.json,以允许人们使用KnpMenu的当前版本,而不仅仅是最新版本。
我找到了一个临时解决方案来使用这两个捆绑包,直到这个票证得到解决。
我在composer.json文件中定义了一个存储库,并操作了sonata管理捆绑包需求("knplabs/knp菜单捆绑包":"dev-master"):
"repositories": [
{
"type": "package",
"package": {
"name": "sonata-project/admin-bundle",
"type": "symfony-bundle",
"description": "Symfony SonataAdminBundle",
"keywords": ["Admin Generator", "admin", "sonata", "bootstrap"],
"homepage": "http://sonata-project.org/bundles/admin",
"license": "MIT",
"authors": [
{
"name": "Thomas Rabaix",
"email": "thomas.rabaix@sonata-project.org",
"homepage": "http://sonata-project.org"
},
{
"name": "Sonata Community",
"homepage": "https://github.com/sonata-project/SonataAdminBundle/contributors"
}
],
"require": {
"symfony/http-foundation": ">=2.1,<2.3-dev",
"symfony/form": ">=2.1,<2.3-dev",
"symfony/validator": ">=2.1,<2.3-dev",
"symfony/security-bundle": ">=2.1,<2.3-dev",
"symfony/routing": ">=2.1,<2.3-dev",
"symfony/config": ">=2.1,<2.3-dev",
"symfony/console": ">=2.1,<2.3-dev",
"symfony/twig-bridge": ">=2.1,<2.3-dev",
"twig/twig": ">=1.10,<2.0-dev",
"knplabs/knp-menu-bundle": "dev-master",
"sonata-project/jquery-bundle": "dev-master",
"sonata-project/exporter": "dev-master",
"sonata-project/block-bundle": "dev-master",
"doctrine/common": ">=2.2,<3.0"
},
"require-dev": {
"jms/translation-bundle": "*"
},
"suggest": {
"sonata-project/doctrine-orm-admin-bundle": "dev-master",
"sonata-project/intl-bundle": "dev-master"
},
"autoload": {
"psr-0": {
"Sonata\AdminBundle": ""
}
},
"target-dir": "Sonata/AdminBundle",
"version": "dev-master",
"source": {
"url": "git://github.com/sonata-project/SonataAdminBundle.git",
"type": "git",
"reference": "0269691d61764798537a2fd3b13bfafbfb387eef"
}
}
}
然后我不得不覆盖admin类中的方法buildSideMenu,因为方法setCurrentUri()已经不存在了(现在命名为setUri(())。我自己的所有管理类现在都扩展了MyAdmin
abstract class MyAdmin extends Admin
{
/**
* Build the side menu related to the current action
*
* @param string $action
* @param SonataAdminBundleAdminAdminInterface $childAdmin
*
* @return KnpMenuItemInterface|boolean
*/
public function buildSideMenu($action, AdminInterface $childAdmin = null)
{
if ($this->loaded['side_menu']) {
return;
}
$this->loaded['side_menu'] = true;
$menu = $this->menuFactory->createItem('root');
$menu->setChildrenAttribute('class', 'nav nav-list');
$menu->setUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo());
$this->configureSideMenu($menu, $action, $childAdmin);
foreach ($this->getExtensions() as $extension) {
$extension->configureSideMenu($this, $menu, $action, $childAdmin);
}
$this->menu = $menu;
}
}
我知道这不是最好的解决方案,但它符合我的目的