1. Go to this page and download the library: Download bor-attila/cakephp-ptj library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
//add multiple variable at once
$this->PhpToJavascript->add([
'user' => $user,
'language' => $lang
]);
//adding simple number if does not exists `var1`
$this->PhpToJavascript->add('var1', 1);
//adding array if does not exists `user`, note that you don't need to call json_encode. The plugin will do it for you
$this->PhpToJavascript->add('user', ['firtname' => 'John', 'lastname' => 'Connor', 'age' => 15]);
//setting and array if exists, will be overwritten
$this->PhpToJavascript->set('user', ['firtname' => 'John', 'lastname' => 'Connor', 'age' => 15]);
//or remove before $this->PhpToJavascript->get() is called
$this->PhpToJavascript->remove('user');
//prints the main javascript file containing the window.__phptojavascript variable and the p function
echo $this->PhpToJavascript->get();
bin/cake generate_php_js
echo $this->PhpToJavascript->get(false);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.