Monday 22 August 2016

PHP Variables to JavaScript Variables in CodeIgniter

Often, you’ll find yourself in situations, where you want to pass some server-side string/array/whatever to your JavaScript. Traditionally, this can be a bit of a pain – especially as your app grows.
“Transform PHP Vars to JavaScript” is a codeIgniter library and it simplifies the process drastically. And it is developed based on “PHP-Vars-To-Js-Transformer” it is developed by JeffreyWay.

How to install

Download the files add put PHPtoJS.php class in your library folder application\libraries\PHPtoJs.php.Now load the library locally or globally.
Locally
Globally
Open you autoload.php file which located at application\config\autoload.php
After loading library, you may use in your controllers as shown below.
Final step – in your layout page or view page add this line, which will print the JavaScript variables.
That is it.

No comments:

Post a Comment

Installation of Drop Box API on Codigniter

As with the YouTube API the first step in getting this sucker setup is getting a developer key by visiting  https://www.dropbox.com/develop...