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
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