PHP Laravel:未找到特征
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27625707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Laravel: Trait not found
提问by andershagbard
I have some trouble with namespace and use.
我在命名空间和使用方面遇到了一些麻烦。
I get this error: "Trait 'Billing\BillingInterface' not found"
我收到此错误:“未找到特征 'Billing\BillingInterface'”
These are the files in my Laravel application:
这些是我的 Laravel 应用程序中的文件:
Billing.php
帐单.php
namespace Billing\BillingInterface;
interface BillingInterface
{
public function charge($data);
public function subscribe($data);
public function cancel($data);
public function resume($data);
}
PaymentController.php
支付控制器.php
use Billing\BillingInterface;
class PaymentsController extends BaseController
{
use BillingInterface;
public function __construct(BillingPlatform $BillingProvider)
{
$this->BillingProvider = $BillingProvider;
}
}
How to i use use and namespace properly?
如何正确使用 use 和 namespace?
回答by robbmj
BillingInterface
is an interface
not a trait
. Thus it can't find the non existent trait
BillingInterface
是interface
不是trait
。因此它找不到不存在的特征
Also you have an interface called BillingInterface
in a namespace called Billing\BillingInterface
, the fully qualified name of the interface is: \Billing\BillingInterface\BillingInterface
此外,您在名为BillingInterface
的命名空间中调用了一个接口Billing\BillingInterface
,该接口的完全限定名称是:\Billing\BillingInterface\BillingInterface
Perhaps you mean
也许你的意思是
use Billing\BillingInterface\BillingInterface;
// I am not sure what namespace BillingPlatform is in,
// just assuming it's in Billing.
use Billing\BillingPlatform;
class PaymentsController extends BaseController implements BillingInterface
{
public function __construct(BillingPlatform $BillingProvider)
{
$this->BillingProvider = $BillingProvider;
}
// Implement BillingInterface methods
}
Or to use it as a trait.
或者将其用作特征。
namespace Billing;
trait BillingTrait
{
public function charge($data) { /* ... */ }
public function subscribe($data) { /* ... */ }
public function cancel($data) { /* ... */ }
public function resume($data) { /* ... */ }
}
Again the modified PaymentsController
, but with fully qualifies names.
再次修改PaymentsController
,但具有完全限定的名称。
class PaymentsController extends BaseController
{
// use the fully qualified name
use \Billing\BillingTrait;
// I am not sure what namespace BillingPlatform is in,
// just assuming it's in billing.
public function __construct(
\Billing\BillingPlatform $BillingProvider
) {
$this->BillingProvider = $BillingProvider;
}
}