绑定依赖注入不起作用。目标不是可实例化的

时间:2014-04-26 14:03:46

标签: php laravel laravel-4

所以这可能很容易,但我已经好几个小时了。错误消息

Illuminate \ Container \ BindingResolutionException
Target [foo\repositories\OrderRepositoryInterface] is not instantiable.

我的界面:

<?php  namespace foo\repositories;

interface OrderRepositoryInterface
{

 public function index(array $dateRange = null, $customerId = null);

}

存储库:

<?php  namespace foo\repositories;
use Carbon\Carbon;
use Order;

class OrderRepository implements OrderRepositoryInterface
{


public function index(array $dateRange = null, $customerId = null)
{
    return 'HI';

}


} 

我的路线档案:

App::bind('foo\repositories\OrderRepositoryInterface.php',
          'foo\repositories\OrderRepository.php');


Route::resource('orders', 'OrdersController');

最后是控制器:

<?php
use foo\repositories\OrderRepositoryInterface;

class OrdersController extends \BaseController
{

protected $order;

/**
 * @param OrderRepositoryInterface $order
 */
public function __construct(OrderRepositoryInterface $order)
{

    $this->order = $order;
}


public function index()
{
    $orders = $this->order->index();
    return $orders;
}

1 个答案:

答案 0 :(得分:1)

App::bind中绑定它们时,尝试从接口和存储库中删除.php More about binding here

App::bind('foo\repositories\OrderRepositoryInterface',
          'foo\repositories\OrderRepository');