传递$ title来查看

时间:2013-10-12 13:58:24

标签: php laravel-4

我正在努力了解Laravel 4:

\控制器\ catalogs.php

class Catalogs_Controller extends BaseController {
  public function get_index(){
    return View::make('catalogs')->with('title', 'Catalog - Home');
  }
}

routes.php文件

 Route::get('/', array('as'=>'home', 'uses'=>'catalogs@index'));

\视图\布局\ default.blade.php

<!DOCTYPE html>
<html>
<head>
<title>{{ $title }}</title>
.....
</html>

\视图\目录\ index.blade.php

 @extends('layouts.default')
 @section('content')
Home Page
 @endsection

但我有一个错误: “类目录不存在”。 哪个可能是问题?

3 个答案:

答案 0 :(得分:1)

基本上一切都是错的,包括文件的名称。以下解决方案

// app/controllers/CatalogsController.php

class CatalogsController extends BaseController {
  public function get_index(){
    return View::make('catalogs/index')->with('title', 'Catalog - Home');
  }
}

// app/routes.php
Route::get('/', array('as'=>'home', 'uses'=>'CatalogsController@get_index'));


// app/views/layouts/default.blade.php

<!DOCTYPE html>
<html>
<head>
<title>{{ $title }}</title>
.....
</html>


// app/view/catalogs/index.blade.php

@extends('layouts.default')

@section('content')
    Home Page
@endsection

现在您必须运行命令composer dump-autoload

请参阅:http://laravel.com/docs/quick

答案 1 :(得分:0)

我对Laravel并不熟悉,但我的猜测是类和文件名之间的连接区分大小写,所以尝试更改

\controllers\catalogs.php

\controllers\Catalogs.php

答案 2 :(得分:0)

我也不熟悉Lara,但我认为你的问题出现在return View::make('catalogs')->with('title', 'Catalog - Home');的第3行

尝试使用return View::make('Catalogs')->with('title', 'Catalog - Home');

干杯...

相关问题