Jeffrey Way創建了一個非常方便的包,用於在Javascript中訪問您的PHP變量 - https://github.com/laracasts/PHP-Vars-To-Js-Transformer。但是,我在數字海洋生產環境中遇到了問題(在本地正常工作)。Javascript namespace not defined Jeffrey Way PHP vars to Javascript
我把它安裝在作曲:
"require":{
"laracasts/utilities":"dev-master"
}
有它安裝在應用程序/配置/ app.php
'providers' => array(
...
...
'Laracasts\Utilities\UtilitiesServiceProvider',
)
跑作曲家,發佈配置文件,並設置在配置元素/laracasts/utilities/config.php文件
return [
/*
|--------------------------------------------------------------------------
| View to Bind JavaScript Vars To
|--------------------------------------------------------------------------
|
| Set this value to the name of the view (or partial) that
| you want to prepend the JavaScript variables to.
|
*/
'bind_js_vars_to_this_view' => 'layouts/partials/_footer',
/*
|--------------------------------------------------------------------------
| JavaScript Namespace
|--------------------------------------------------------------------------
|
| By default, we'll add variables to the global window object.
| It's recommended that you change this to some namespace - anything.
| That way, from your JS, you may do something like `Laracasts.myVar`.
|
*/
'js_namespace' => 'MyApp'
];
但我收到「Uncaught ReferenceError:MyApp is not defined」錯誤。有任何想法嗎?
我確實改變了你的建議,但仍然無效。我在本地使用反斜槓,它工作正常。 –