问题: 类PostRepostioryInterface在PostController.php 或与命名空间我甚至已经得到修补类未找到行4 应用程序\型号\接口\ PostRepositoryInterface找不到如何laravel注册一个命名空间4
问题:如何在laravel 4中注册一个名称空间?我需要做什么才能让L4在这个命名空间识别类/接口?
Larave 3曾在一个ClassLoader的命名空间$静态对象,在那里你可以通过
Autoloader::namespaces(array(
'App\Models\Interfaces' => path('app').'models/interfaces',
));
我不知道我是否有这个权利的laravel 3,但无论哪种方式,自动装载不存在添加的命名空间Laravel 4和ClassLoader存在,但Laravel 4中ClassLoader中不存在方法命名空间。
我已经看过这个,但它似乎没有注册命名空间的工作。 Using namespaces in Laravel 4
实施例结构:
app/models/interfaces
PostRepostitoryInterface.php
app/models/repositories
EloquentPostRepository.php
namespaces:
App\Models\Repositories;
App\Models\Interfaces;
文件:
PostRepositoryInterface.php
<?php namespace App\Models\Interfaces;
interface PostRepositoryInterface {
public function all();
public function find($id);
public function store($data);
}
EloquentPostRepository.php
<?php namespace App\Models\Repositories;
use App\Models\Interfaces\PostRepositoryInterface;
class EloquentPostRepository implements PostRepositoryInterface {
public function all()
{
return Post::all();
}
public function find($id)
{
return Post::find($id);
}
public function store($data)
{
return Post::save($data);
}
}
PostController.php
<?php
use App\Models\Interfaces\PostRepositoryInterface;
class PostsController extends BaseController {
public function __construct(PostRepositoryInterface $posts)
{
$this->posts = $posts;
}
感谢
这是另一个问题,如果有人想看看它。 http://stackoverflow.com/questions/15236878/laravel-4-target-interface-is-not-instantiable – isimmons 2013-03-06 00:38:48