【发布时间】:2014-05-23 06:40:23
【问题描述】:
Jeffrey Way 创建了一个非常方便的包,用于在 Javascript 中访问您的 PHP 变量 - https://github.com/laracasts/PHP-Vars-To-Js-Transformer。但是,我在 digitalocean 生产环境中遇到了这个问题(在本地工作正常)。
我已经在 composer 中安装了它:
"require":{
"laracasts/utilities":"dev-master"
}
将其安装在 app/config/app.php 中
'providers' => array(
...
...
'Laracasts\Utilities\UtilitiesServiceProvider',
)
运行 composer,发布配置文件并在 config/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'
];
但我收到“未捕获的 ReferenceError:未定义 MyApp”错误。有任何想法吗?
【问题讨论】:
标签: javascript php laravel