2014-04-11 18 views
0

我是laravel的新手。我有一個關於生根和意見的問題。我正在學習一個教程。但教程和輸出的輸出結果不一樣。 當我插入這個在地址欄本地主機/ laravel/2nd_project /公/作者,我沒有產生這應該是有一個輸出就像教程控制器和路由不會生成index.php我正在使用laravel 4.1

這裏的index.php文件是控制器/ 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'=>'[email protected]_index')); 

的意見/作家/ index.php文件

<h1>Hi User!!</h1> 
+0

這是意見/authors/index.php

嗨用戶!

Kerbs

+0

你會得到什麼?您的Laravel安裝是否成功?你見過這個嗎? https://pbs.twimg.com/media/BLYFfmLCAAEHcZL.png –

+0

是的,我已經看到了,它是成功的,實際上我已經遷移並使用模式創建數據庫。 – Kerbs

回答

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名爲BaseController.php文件,如果你」從AuthorsController重新延伸BaseController

在routes文件,你可以做到以下幾點:

Route::get('authors', array('uses'=>'[email protected]')); 

如果你想在Laravel 4 REST風格的控制器,你可以在官方文檔在這裏閱讀更多關於它:http://laravel.com/docs/controllers#restful-controllers

+0

感謝您的信息,但它仍然有同樣的問題。 404找不到 – Kerbs

+0

你在Apache中啓用了'mod_rewrite'插件嗎? – SUB0DH

+0

不,我使用的是wamp服務器,我可以在哪裏找到它? – Kerbs