dongle7553 2015-06-23 18:41
浏览 64
已采纳

如何在Polymer中使用PHP?

I have a problem including PHP code in my Polymer project. I have tried to set up a ".htaccess" file on my server, but it did not work. Moreover I do not think there is a easy way to change the "index.html" file to a "index.php" file because it is refered to this file in many other files, I do not know. I am using a gulp server on my local computer and I have tried to include a PHP support there but it failed. This is the code of the gulpfile (only minimal modification form the original file):

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);
});
...
  • 写回答

1条回答 默认 最新

  • doujiabing1228 2015-06-23 19:16
    关注

    Something like this in your .htaccess file should force the server to treat all the listed file types (extensions) as PHP:

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

    Note the last one is ".html". However, as I noted in the comment, you're not quoting PHP, but JavaScript, and I'd hazard a guess you might just be in over your head a bit.

    Good luck. :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题