P
P
pyatin2012-07-17 01:24:47
PHP
pyatin, 2012-07-17 01:24:47

Using inline JavaScript in a view

Hello.

Interested in the following how do you feel about using inline JavaScript'a
inside the usual php view mvc frameworks (ZF, yii)? There are pros and cons both with and without use.
In theory, it is worth separating js and css, etc. (as google advises), but this is not always convenient. It is much easier to
generate js code in view and pass php variables to it than to look for and use some kind of js and php interaction methods (ajax, jquery.metadata ect).

I try not to use inline js at all, to pass any data from php to javascript
I use either query.metadata or html generation and put all the javascript into a file.
Thus, in my opinion, the code becomes more predictable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wott, 2012-07-17
@Wott

In my opinion, you are confusing soft with warm
. It's good when the code related to one functionality is nearby. Conversely, logically different pieces of code are separated. Therefore, business logic must be separated from the presentation. But for this reason, it would be good not to separate the code that is responsible for the presentation.
Personally, I do small inserts right in the code. Especially if these are all sorts of plugins :) Small inserts in a large file are bad - they get lost against the background of others and are often more difficult to maintain.
Another advantage is that the code is immediately available and there are no certain problems with downloading the file. True, this is more about styles, but oh well.
The only time it's worth taking out JS inserts in a separate file is when several pieces interact with each other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question