简体   繁体   中英

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. 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. Is that right?

…PHP integrated into the JavaScript framework…

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. 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.

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. Hope it helps you to find your way through.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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