簡體   English   中英

安裝了Laravel 5,但是刀片和路由無法正常工作,該怎么辦?

[英]Got Laravel 5 installed but blade and routing not working correctly, what to do?

現在已經停滯了2天,我已經廣泛研究了互聯網,但是無法正常工作。 我已經使用composer安裝了laravel 5,並遵循了一些教程,但是由於某些原因,當我創建新視圖時,它會重新路由到我的公用文件夾,而不是視圖文件夾。 安裝目錄:c:\\ xampp \\ htdocs \\ projectname \\我在http.conf中啟用了全部覆蓋,我的根目錄設置為:“ C:/ xampp / htdocs / projectname / public”

當我在瀏覽器中鍵入localhost時,welcome.blade.php會加載並正確顯示。 我創建了一個新的控制器:

<?php
class authors extends Controller{   
public $restful=true;
public function get_index(){
        // return view::make('authors.index');
        $view= view::make('authors.index',array('name'=>'My Name'))->with ('email','28');
        $view->location='amsterdam';
        return $view;
}}

route.php如下所示:

Route::get('/', function () {
    return view('welcome');
});

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

在內部視圖中,我創建了一個名為authors的文件夾,並在該文件夾中放置了index.blade.php:

測試

現在,當我嘗試查找localhost / authors時,它應該重定向到子文件夾作者並打開index.blade.php,但是我得到了:

 Index of /authors [ICO] Name Last modified Size Description [PARENTDIR] Parent Directory - [TXT] index.blade.php 2015-08-04 07:46 209 Apache/2.4.12 (Win32) OpenSSL/1.0.1m PHP/5.6.11 Server at localhost Port 80 

我可以定向到公用文件夾並在其中調用index.php,但是刀片模板在此處不起作用,並且我無法從我放入的$ view中回憶起日期(例如$ name,$ email等)。 。 我檢查了文件夾權限,並確保正確設置了文件夾權限。 我還嘗試了以下操作:
-重新安裝laravel(努力工作)
-從WAMP開始並切換到XAMP(正在工作)

我剛剛開始使用Laravel,因為它看起來非常用戶友好且節省時間,因為我對sql查詢有點厭煩,並且我需要一個可靠的密碼保護框架。 我已經准備好使用html,css和php的網站。 現在,最后一步是實施laravel,以改善未來的功能和穩定性。 我真的被困在這里,請幫幫我,這樣我就可以完成我的網站並以安全的方式使其在線

由於我已經使用了幾天,所以並不是所有人都對laravel太熟悉。 也許在下面嘗試以下方法而不是制作一個數組?

Route::get('authors','authors@index');

您必須在apache配置中啟用mod_rewrite。 打開httpd.conf(或apache2.conf,這取決於您的Apache安裝),然后取消注釋以“ LoadModule rewrite_module”開頭的行。

確實已經在配置中啟用了mod_rewrite。 我的一位好友走進來,幫助了我。 看起來我在Laravel5中使用了一些舊的Laravel 4代碼。

將控制器重命名為:AuthorController,將函數更改為index,並刪除了public $ restful = true。 路線更改為:

Route::get('authors', array('uses'=>'AuthorController@index'));

最初,我將頁面放在公用文件夾中。 .htaccess如下所示:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

基本上將我重定向到index.php

希望這對其他人有用,感謝您抽出寶貴的時間來答復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM