2015-06-23 56 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