简体   繁体   English

Ember.js与PHP

[英]Ember.js with PHP

I can't find a clear answer to this question anywhere so here it goes. 我无法在任何地方找到这个问题的明确答案。 Looking at Ember.js , it seems like you can build a full fledged application with just JavaScript, HTML, and CSS. 看看Ember.js ,看起来你可以用JavaScript,HTML和CSS构建一个完整的应用程序。 My question is, is it advisable to do it that way? 我的问题是,这样做是否明智? I see no examples with PHP integrated into the JavaScript framework so, to me, it seems like an either/or kinda deal. 我没有看到将PHP集成到JavaScript框架中的示例,因此,对我来说,它似乎是一种或者有点不同的交易。 Is that right? 是对的吗?

…PHP integrated into the JavaScript framework… ... PHP集成到JavaScript框架中......

I don't know what kind of answer your are expecting here... As PHP is a server-side language, what I do is code my REST APIs on the server side in PHP, an all my application logic is written on Ember.js, and executed on the client. 我不知道你在这里期待什么样的答案......由于PHP是一种服务器端语言,我所做的是在PHP服务器端编写我的REST API,我的所有应用程序逻辑都写在Ember上。 js,并在客户端执行。 On another part, the server generates some of the needed handlebars templates, and serves them to the client on the first application load. 另一方面,服务器生成一些所需的把手模板,并在第一次应用程序加载时将它们提供给客户端。

If you want to call the data from PHP and send it to Emberjs, you may need to use JQuery Ajax functions. 如果要从PHP调用数据并将其发送到Emberjs,则可能需要使用JQuery Ajax函数。

For example. 例如。

$.ajax ({
  type: "POST",
  url: "../model/my_model.php",
  data:{choosen_id: choosen_id,contact_age: contact_age },
    //data:"contact_id_choosen="+ choosen_id,
  }).done(function(data) {

  data_formated = '<div class="formated_data">'+data+'</div>';
  $(".dialog-window").html(data_formated);
    //return result
  }).fail(function(x,s,e) {
    alert(s+": "+e);
    alert('detail button failed!');
    //alert(result);
  });//$.ajax END

Above Ajax code sample can insert a correctly formatted PHP data array into the EmberJS. 上面的Ajax代码示例可以将正确格式化的PHP数据数组插入到EmberJS中。 Hope it helps you to find your way through. 希望它能帮助您找到自己的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM