{"action":"closed","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9609","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9609/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9609/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9609/events","html_url":"https://github.com/yiisoft/yii2/issues/9609","id":105067329,"number":9609,"title":"forwarding php variables to javascript by JsExpression","user":{"login":"atcq1","id":10836257,"avatar_url":"https://avatars.githubusercontent.com/u/10836257?v=3","gravatar_id":"","url":"https://api.github.com/users/atcq1","html_url":"https://github.com/atcq1","followers_url":"https://api.github.com/users/atcq1/followers","following_url":"https://api.github.com/users/atcq1/following{/other_user}","gists_url":"https://api.github.com/users/atcq1/gists{/gist_id}","starred_url":"https://api.github.com/users/atcq1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atcq1/subscriptions","organizations_url":"https://api.github.com/users/atcq1/orgs","repos_url":"https://api.github.com/users/atcq1/repos","events_url":"https://api.github.com/users/atcq1/events{/privacy}","received_events_url":"https://api.github.com/users/atcq1/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:need%20more%20info","name":"status:need more info","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-06T02:54:28Z","updated_at":"2015-09-07T20:43:42Z","closed_at":"2015-09-07T20:43:42Z","body":"Now many widgets js code is constructed using the concatenation, it is not very convenient.\r\nexample:\r\n```php\r\n$myId = '#div555';\r\n$myLink = Url::toRoute('create');\r\nnew JsExpression(\"$(myId).load(myLink);\", ['myId' => $myId, 'myLink' => $myLink']);\r\n```\r\ngenerates:\r\n```html\r\n<script>\r\nvar myId = '#div555';\r\nvar myLink = 'http://yiisite.ru/controller/create';\r\n$(myId).load(myLink);\r\n</script>\r\n```\r\n\r\nOR with templating\r\n\r\nexample:\r\n```php\r\n$myId = '#div555';\r\n$myLink = Url::toRoute('create');\r\nnew JsExpression(\"function jsExample(){ #jsvars# $(myId).load(myLink);}\", \r\n    ['myId' => $myId, 'myLink' => $myLink], \r\n    '#jsvars#');\r\n```\r\ngenerates:\r\n```html\r\n<script>\r\nfunction jsExample()\r\n{\r\n   //jsvars:\r\n   var myId = '#div555';\r\n   var myLink = 'http://yiisite.ru/controller/create';\r\n   $(myId).load(myLink);\r\n}\r\n</script>\r\n```\r\n\r\n\r\n\r\n"}}