0

當嘗試這樣做,調用我的回購類的任何行動,我得到孩子回購界面上出現以下錯誤:Laravel 4接口文件錯誤:「語法錯誤,意想不到的‘接口’(T_INTERFACE)」

"syntax error, unexpected 'interface' (T_INTERFACE)" 

這是錯誤的來源,回購類的代碼,而孩子回購接口文件:

<?php namespace MyProj\Repository\Parent; 

use MyProj\Parent; 
use MyProj\Parent\ChildRsrc as ChildRsrc; 

class EloquentParentRepo implements ParentRepoIfc 
{ 
    public $childRepo; 

    public function __construct(ChildRsrcRepoIfc $childRepo) 
    { 
     $this->childRepo = $childRepo; 
    } 
    // ... 
    } 

和孩子回購接口文件:

<?php namespace MyProj\Repository\Parent; 

interface ChildRscrRepoIfc // the error info points to this line 
{ 
    public function all(); 

    public function create($input); 

    public function delete($id); 

    public function find($id); 
} 

它的結構與項目中的其他代碼一樣工作正常。 ChildRsrcRepoIfc及其具體實現(EloquentChildRscrRepo)與此處引用的其他所有內容在同一個父命名空間中。我已經三次檢查拼寫錯誤的拼寫。一如既往,任何幫助表示讚賞。

更新:我想在父類中去除DI和使用直接實例化,但仍然得到了同樣的錯誤:

class EloquentParentRepo implements ParentRepoIfc 
{ 
    public function __construct() 
    { 
     $this->childRepo = new ChildRsrcRepoIfc; 
    //... 

我仔細檢查了,我做如下的回購SVC提供商綁定:

class RepositoryServiceProvider extends ServiceProvider 
{ 
    public function register() 
    { 
    $this->app->singleton(
     'MyProj\Repository\Parent\ChildRsrcRepoIfc', 
     'MyProj\Repository\Parent\EloquentChildRsrcRepo' 
    ); 
+0

你的'EloquentChildRsrcRepo'在哪裏?你的單身人士正在偷偷摸摸地不存在? –

+0

所有文件位於同一個名稱空間文件夾「MyProj \ Repository \ Parent」中。有許多子表我已經爲其設置了獨立的ChildRsrcNRepoIfc和EloquentChildRsrcNRepo文件。這些子表和它們的回購對應表大多在父項的上下文中引用,所以我以這種方式組織它。 – Bluesail20

回答

2

不應該這個是?:

class RepositoryServiceProvider extends ServiceProvider 
{ 
    public function register() 
    { 
    $this->app->singleton(
     'MyProj\Repository\Parent\ChildRsrcRepoIfc', 
     'MyProj\Repository\Parent\EloquentParentRepo ' 
    ); 

東西使得h一旦在使用Laravel的IoC自動解析在寫

<? 

而不是

<?php 

如果你這樣做Laravel找不到文件appened給我。檢查你的文件。

+0

嗯......我將ParentRepoIfc綁定到EloquentParentRepo,並將每個子RepoIfc綁定到他們自己的EloquentChildNRepo。如果我將它們綁定到父級 - 那麼我怎樣才能調用子級repo上的方法來在子級表上執行DML? – Bluesail20

+0

是的,我認爲你可能會涉及更多的文件,但PHP正在抱怨它不應該這樣做,所以你必須在代碼中有些奇怪的東西。編輯添加一個小東西。 –

+0

我通過仔細刪除然後重新輸入文件中的所有空格來使錯誤消失。我認爲一些腐敗的隱形人物可能是由外部來源複製粘貼的結果。我的其他幾個文件也有同樣的問題。感謝您經常光臨和幫助,@安東尼奧 – Bluesail20

相關問題