3
我在命名空間和使用方面遇到了一些麻煩。PHP Laravel:未找到特徵
我得到這個錯誤: 「特質的 '結算\ BillingInterface' 未找到」
這些都是在我的Laravel應用程序的文件:
Billing.php
namespace Billing\BillingInterface;
interface BillingInterface
{
public function charge($data);
public function subscribe($data);
public function cancel($data);
public function resume($data);
}
PaymentController.php
use Billing\BillingInterface;
class PaymentsController extends BaseController
{
use BillingInterface;
public function __construct(BillingPlatform $BillingProvider)
{
$this->BillingProvider = $BillingProvider;
}
}
如何正確使用use和namespace?
我不想執行到控制器。 – andershagbard
@andershagbard然後你將不得不做一個實現BillingInterface方法的特質。然而,特徵不是PHP中的類型,也不能實現iterface,因此您將失去類型層次結構,因爲「PaymentsController」不是「BillingInterface」。另一種方法也許最好的方法是向控制器注入一個可以計費的對象。也許這就是「BillingPlatform」的重點,但我無法確定。 – robbmj
這不是我在構造函數中做的事嗎? – andershagbard