【问题标题】:Target Interface is not instantiable. Laravel 4目标接口不可实例化。拉拉维尔 4
【发布时间】:2014-08-23 16:39:31
【问题描述】:

当我搜索错误“目标接口不可实例化”时,我得到了很多结果。不知何故,我仍然找不到解决问题的方法。

我不知道哪里出了问题。

PartnerController.php

<?php use CmsBlox\MOD\PartnerInterface;


class PartnerController extends BaseController {
    public function __construct(PartnerInterface $partner)
    {
        $this->partner = $partner;
    }

    public function Get()
    {
        return "I'm the Get function in class PartnerController";
    }
}

PartnerServiceProvider.php

<?php namespace CmsBlox\Providers;

use App, Illuminate\Support\ServiceProvider;

class PartnerServiceProvider extends ServiceProvider {
    public function register()
    {

    }

    public function boot() 
    {
        app::bind('CmsBlox\MOD\PartnerInterface') ;
    }
}

Routes.php

app::bind('CmsBlox\MOD\PartnerInterface') ;

PartnerInterface.php

<?php namespace CmsBlox\MOD;

interface PartnerInterface {
    public function get();
}

我还在 App.php 中添加了提供程序(用于测试 routes.php 中的 app::bind())

'CmsBlox\Providers\PartnerServiceProvider'

据我所知,每个文件都应该是正确的。不知怎的,我错过了一些东西!

【问题讨论】:

    标签: php laravel interface laravel-4


    【解决方案1】:

    我刚刚找到了答案!感谢 Laravel.io 论坛。

    <?php use CmsBlox\MOD\PartnerInterface;
    
    class PartnerController extends BaseController implements PartnerInterface {
    
        public function get() {...}
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-20
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 2023-03-03
      相关资源
      最近更新 更多