Welcome Guest, Not a member yet? Register   Sign In
Using "PHP" inside front end scripts
#3

I prefer to write my JavaScript to retrieve any data it needs from hidden fields or data-* attributes in the HTML, rather than making it aware of PHP variables passed from a controller. However, I'm probably as guilty as anyone when it comes to occasionally echoing a value into a script or even building JavaScript in PHP. In the end, the larger concern is about putting logic into PHP code in a view (rather than just retrieving the values of variables).

I think you'll find that creating JavaScript which is as independent of your PHP environment as possible has long term benefits, though. It certainly makes it easier if you need to get the same functionality in another project, or even another portion of the same site where you may want a similar visualization for some unrelated data.
Reply


Messages In This Thread
RE: Using "PHP" inside front end scripts - by mwhitney - 07-02-2015, 08:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB