php - How to Pass the Controller Data to JS File in CakePHP 3.0 -


in cakephp 2.0, i've used link below pass controller data js file. however, can longer use method anymore cakephp 3.0 has removed js helper.

is there new technique me pass controller data js file or alternative method beside using js helper link below?

http://www.php-dev-zone.com/2014/01/how-to-pass-controller-data-to-js-file.html

relevant code:

public function beforerender() {     // setting jsvariables array holds     // variables used in js files.     $this->set('jsvars', $this->_jsvariables); } 
<?php echo $this->html->scriptblock('var jsvars = '.$this->js->object($jsvars).';'); ?> 

just check jshelper::object() method doing, , manually.

https://github.com/cakephp/.../2.7.0/lib/cake/view/helper/jsbaseenginehelper.php#l127

it's call json_encode(), replace helper method call accordingly:

<?php echo $this->html->scriptblock('var jsvars = ' . json_encode($jsvars) . ';'); ?> 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -