There are already a few posts on SO discussion whether this architecture is a good idea or bad idea. For many reasons within our company including the existing programming talent, we've decided to use Java for the backend and PHP for the front end. Our objective is something like...
Java - Models/Controllers
PHP - Views
We're working on building a prototype of the interaction between Glassfish and Apache. One thing we're still working on is when a user visits http://domain.com/login.html and they login, that login will be sent to the Glassfish controller which exists somewhere like /login.java
. We can do that no problem, the trouble is getting the view to be rendered at that URL.
Has anyone does this with PHP or any other technologies?
Languages used for the front end are HTML, CSS, and JavaScript while those used for the backend include Java, Ruby, Python, and . Net.
There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.
In a nutshell: While comparing the Java vs PHP performance, Java is clearly a winner as it is faster and efficient than PHP to write enterprise applications. Like developers have to build mobile enterprise applications to streamline complex business processes and operations.
PHP is a programming language for back end development only. JavaScript, in turn, was initially designed as a front end development language. But with the introduction of Node.
Have you considered setting up a soap/rest server in java and having PHP talk to that? I imagine that would be much simpler than what you're trying to achieve.
I am sorry to bring this up but it seems like it would make things a lot simpler to stick with just one of these languages. If you are using PHP to add more logic into your view, it might be worth taking a look at Velocity. It allows you to access and create variables, iterate through lists, use conditionals, define macros, make method calls, etc. This seems like it might make things much cleaner. However, it is usually a good idea to try to keep as much logic out of your templates as possible.
If you would like to use PHP because that is what is required I would suggest taking a look at using web services to communicate. Take a look at Googles GSON library. It is really nice tool (on the java side) for mapping JSON Objects to your model (and vice versa).
On your front-end, it might also be worth taking a look at Backbone. It is a tool that makes it simple to mock up your model Objects and bind events to them, or add tie them directly to fields, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With