控制器和路由没有使用laravel 4.1生成index.php我

时间:2014-04-11 14:37:07

标签: laravel-4

我是laravel的新手。我有关于root和视图的问题。我正在学习一个教程。但是教程和输出的输出不一样。 当我在地址栏localhost / laravel / 2nd_project / public / authors中插入这个时,我没有生成index.php,它应该像教程一样有输出

这是controllers / authors.php

<?php
  class Authors_Controller extends Base_Controller{
      public $restful = true;

  public function get_index(){
      return View::make('authors.index');
   }
}

应用程序/ routes.php文件

<?php
   Route::get('/', function()
   {
     return View::make('hello');
    });

    Route::get('authors',array('uses'=>'Authors_Controller@get_index'));

视图/作者/ index.php的

<h1>Hi User!!</h1>

1 个答案:

答案 0 :(得分:0)

看起来你正在遵循基于Laravel 3的教程。在Laravel 4中,情况发生了变化。在laravel 4中,控制器名称必须遵循模式SomethingController,因此控制器的文件名必须为AuthorsController.php,类名为AuthorsController

因此,在控制器目录中,您将拥有一个名为AuthorsController.php的文件,如下所示:

<?php
  class AuthorsController extends BaseController {
    public function getIndex()
    {
        return View::make('authors.index');
    }
}

此外,如果您需要一个名为BaseController.php的文件与BaseController类,如果您从BaseController扩展AuthorsController

在路线文件中,您可以执行以下操作:

Route::get('authors', array('uses'=>'AuthorsController@getIndex'));

如果你想在Laravel 4中使用RESTful控制器,你可以在官方文档中阅读更多相关内容:http://laravel.com/docs/controllers#restful-controllers