Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mix Javascript and PHP in my design model

I'm developing a web application and I'm using PHP and Javascript. Today, I'm starting to draw all the design class diagrams, but I don't know exactly how to mix both technologies.

I think that something like the following should be good:

UML example diagram

But, really, I'm not sure if typing the .php extension in the class name is sufficiently clear, or what I need is to separate diagrams in two: one for Javascript classes and another one for PHP classes.

I'm using CodeIgniter (MVC pattern) and Javascript. Any suggestion will be really appreciated.

Thanks!

like image 268
Fran Verona Avatar asked Feb 01 '11 11:02

Fran Verona


People also ask

Can you mix PHP and JavaScript?

Besides, PHP and JavaScript similarities, these two languages are a powerful combination when used together. Large numbers of websites combine PHP and JavaScript – JavaScript for front-end and PHP for back-end as they offer much community support, various libraries, as well as a vast codebase of frameworks.

Do PHP and JavaScript do the same thing?

JavaScript is used to create real-time games and applications, mobile applications etc. A PHP program is used to create dynamic pages, send cookies, receive cookies, collect form data, etc. JavaScript is case sensitive in case of functions. PHP is not case sensitive in case of functions.

Is PHP faster than JavaScript?

The comparison between PHP vs JavaScript ends with the score 3 to 5 – JavaScript beats PHP. Both languages are fairly good in terms of community support, extensibility, and apps they are suited to. JavaScript is certainly more efficient in terms of speed and universality.

Is PHP harder than JavaScript?

While PHP is easier to learn, it is capable of building complete websites. On the other hand, we have more complex JavaScript, but it is one of the most popular languages. For front-end development, you should definitely choose JavaScript as PHP is only for server-side development.


1 Answers

Usually, you don't want to do this. It's a problem of latency when viewing the web page in a browser. Each separate javascript file defeats caching and requires additional transfer time before a page can load. It's commonly advised to combine JS files wherever possible and practical to better take advantage of browser caching. So my first suggestion is to not arbitrarily split up your JS for architectural reasons...

Now, with that said, to answer you question in entirety, I think it depends on how you view JS. If you're looking at it form the perspective that it enhances your PHP application, then dividing it up along side your views is not bad (the above suggestion not withstanding).

However, I usually see JS as a separate application layer on top of the PHP application. The JS interacts with the PHP layer through defined APIs. So it's basically just a full blown GUI application that just so happens to use the API defined by the PHP application. So with that in mind, I usually build the JS application with its own architecture that's more dependent on itself then the PHP application. So in other words, just because a piece of the JS application interacts with PHP doesn't mean that the piece of code belongs with the PHP application.

Does that make sense?

like image 132
ircmaxell Avatar answered Sep 18 '22 01:09

ircmaxell