问题描述
我正在将旧代码迁移到5.7,并且在帮助程序方面遇到了一个奇怪的问题.我正在使用两个程序包-我们将它们称为A和B.程序包A一个实现了ServiceProvider.我想在程序包B的控制器中使用它,但似乎无法正确找到它.我在程序包A的install()
函数中对其进行配置,如下所示:
I'm migrating old code to 5.7, and I'm running into a weird issue when it comes to helpers. I'm working with two packages - let's call them A and B. Package A one implements a ServiceProvider. I would like to use it in a controller in package B, but it seems unable to find it properly. I'm configuring it in the install()
function of package A, as follows
$providers = Config::get('providers');
if (!$providers) {
$providers = array('group_membership' => '\Concrete\Package\A\Src\GroupMembership\GroupMembershipProvider');
} else {
$providers['group_membership'] = '\Concrete\Package\A\Src\GroupMembership\GroupMembershipProvider';
}
Config::set('providers', $providers);
然后在ServiceProvider本身中,将其相应地绑定;
And in the ServiceProvider itself, I bind it accordingly;
<?php namespace Concrete\Package\A\Src\GroupMembership;
use \Concrete\Core\Foundation\Service\Provider as ServiceProvider;
class GroupMembershipProvider extends ServiceProvider
{
public function register() {
$this->app->bind('helper/group_membership', 'Concrete\Package\A\Src\GroupMembership\GroupMembershipProvider');
}
}
然后,当我想在A包中使用它时,效果很好:
Then when I want to use in package A, this works just fine:
$helper = Core::make('helper/group_membership');
但是当我在程序包B中这样做时,它会告诉我:
But when I do that in package B, it tells me:
Class helper/group_membership does not exist
除了将两个软件包合并在一起之外,我该怎么办?可能是什么原因造成的?
What could I do, except for merging the two packages together? What may be causing this?
推荐答案
注册软件包的正确方法是实例化一个新的\Concrete\Core\Foundation\Service\ProviderList
并使用registerProvider
方法.
The proper way to register a package is to instantiate a new \Concrete\Core\Foundation\Service\ProviderList
and use the registerProvider
method.
// Register our service provider
$list = new ProviderList(\Core::getFacadeRoot());
$list->registerProvider('Concrete\\Package\\LegacySample\\Libraries\\ServiceProvider');
这篇关于Concrete5 5.7:使用ServiceProvider交叉打包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!