Laravel 修改默认View模版加载路径

在laravel框架中,加载模版页面会默认到resources/views目录中寻找,如果想修改默认的加载路径,可通过如下方法:

use Illuminate\Support\Facades\View;
use Illuminate\View\FileViewFinder;

protected function initViewPath($relative_path = '/'){
        $path=[config('app.absolutely_view').$relative_path];
        $finder =new FileViewFinder(App::make ('files'),$path);
        View::setFinder ($finder);
    }
public function gamesTangram (Request $request){
        $this->initViewPath($request->getRequestUri());
        return view('index');
    }

其中config('app.absolutely_view')为配置文件中定义的绝对路径,如:

'absolutely_view' => env('VIEW_PATH', '/home/work/template/template_courseware'),

 

你可能感兴趣的:(PHP)