2014-10-09 48 views
-2

我需要創建GET css文件在我的控制器laraven,因爲我有一個問題,我回來的結果是一個正常的文件(文本文件),CSS,而不是一個CSS文件用PHP創建laravel

我routes.php文件文件包含:

Route::get('/css/{css}.css', '[email protected]') 
->where('css','[A-Za-z]+'); 

FileController.php:

<?php 

class FileController extends \BaseController { 

    public function GetCss($css) 
    { 
     $file = File::get(app_path()."\css\\".$css.".css"); 
     return $file; 
    } 

} 

和我css.css文件包含:

body 
{ 
    background: #f00; 
} 

瀏覽器的返回是:

body{ background: #f00; } 

和源(檢查元素/ Ctrl + U):

body 
{ 
    background: #f00; 
} 

什麼,我必須做一個CSS文件的工作?

+0

我不明白的問題,或者你是什麼試圖去做。 – will 2014-10-09 22:44:15

+0

請澄清它,我以爲你做公用文件夾中的所有CSS樣式? – nCore 2014-10-09 22:53:36

+1

這不是什麼laravel是爲 – 2014-10-09 22:54:44

回答

0

你的問題需要更多的澄清,我想你正在試圖建立一個CDN或類似的東西。

當你說「我必須做一個CSS文件來工作?」,我認爲你需要指定響應頭:

public function GetCss($css) 
{ 
    $file = File::get(app_path()."\css\\".$css.".css"); 
    $response = Response::make($file); 
    $response->header('Content-Type', "text/css"); 
    return $response; 
} 
+0

是+/-這,但與此我不能在我的css文件中執行php代碼,我需要執行 – 2014-10-11 23:41:26

+0

我測試這個並使用php代碼'公共函數GetCss($ css){$ file = File :: get(app_path() 。 「\ CSS \\」 $ CSS)。 「PHP」; $ response = Response :: make($ file); $ response-> header('Content-Type',「text/css」);返回$ response; ''但不工作 – 2014-10-12 00:19:22