I am a very newbie to Dart. The today's question is: How to combine a PHP project with Dart code? The most typical example is passing json_encoded variables to JavaScript or Dart with <?php echo ?>, or, sometimes, including some echo's in the HTML code. But if I work with the Dart editor and test in Chromium, I have no access to my locally running PHP server (e.g. Xampp).

How should I deal with that, what is the practice?

有帮助吗?

解决方案

You don't generate content or scripts in PHP to be displayed by Dart when using Dart. Dart is best used with Single Page Application Frameworks. (AngularDart, PolymerDart)

Idealy, you build the entire client code in Dart. Dart communicates with the server using HTTP requests or WebSocket to send or fetch the data. The data format is usually JSON but can also be any other format (images, audio, video, ...). Only data is sent between Dart client and PHP server.

When you build Dart to JavaScript the generated output can be integrated with your PHP like some other static content (HTML, Images, ...).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top