2015-06-23 60 views
0

我有一個問題,包括我的聚合物項目中的PHP代碼。我試圖在我的服務器上設置一個「.htaccess」文件,但它不起作用。此外,我不認爲有一種簡單的方法可以將「index.html」文件更改爲「index.php」文件,因爲它被引用到許多其他文件中的此文件中,我不知道。我在本地計算機上使用了一個gulp服務器,並試圖在其中包含一個PHP支持,但它失敗了。這是gulpfile的代碼(只需稍加修改形成的原始文件):如何在聚合物中使用PHP?

var gulp = require('gulp'); 
var connect = require('gulp-connect-php'); 
... 
// Watch Files For Changes & Reload 
gulp.task('serve', ['elements', 'images'], function() { 
    connect.server({}, function(){ 
    browserSync({ 
     notify: false, 
     snippetOptions: { 
     rule: { 
      match: '<span id="browser-sync-binding"></span>', 
      fn: function (snippet) { 
      return snippet; 
      } 
     } 
     }, 
     // Run as an https by uncommenting 'https: true' 
     // Note: this uses an unsigned certificate which on first access 
     //  will present a certificate warning in the browser. 
     // https: true, 
     server: { 
     baseDir: ['.tmp', 'app'], 
     routes: { 
      '/bower_components': 'bower_components' 
     } 
     } 
    }); 
    }); 

    gulp.watch(['app/**/*.html'], reload); 
    gulp.watch(['app/styles/**/*.css'], ['styles', reload]); 
    gulp.watch(['app/elements/**/*.css'], ['elements', reload]); 
    gulp.watch(['app/{scripts,elements}/**/*.js'], ['jshint']); 
    gulp.watch(['app/images/**/*'], reload); 
}); 
... 
+0

您顯示的代碼不是PHP,而是JavaScript。 –

+0

這是gulp配置文件的代碼 – ff17x3

回答

1

像這樣的事情在你的.htaccess文件應該強制服務器對待所有列出的文件類型(擴展名)爲PHP:

AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .html 
DefaultType application/x-httpd-php5 

注意最後一個是「.html」。然而,正如我在評論中指出的那樣,你並沒有引用PHP,而是JavaScript,而且我猜測你可能只是在頭腦中一點點。

祝你好運。 :-)

+0

它的工作原理。解決方案是使用xampp服務器而不是吞吐量。我敢肯定有一種方法可以做到這一點,但這對我很有用。 – ff17x3