Javascript命名空间没有定义Jeffrey Way PHP vars to Javascript

时间:2014-04-09 20:17:51

标签: javascript php laravel

Jeffrey Way创建了一个非常方便的包,用于在Javascript中访问PHP变量 - https://github.com/laracasts/PHP-Vars-To-Js-Transformer。但是,我在digitalocean生产环境中遇到此问题(在本地工作正常)。

我把它安装在作曲家:

"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未定义”错误。有任何想法吗?

2 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为没有这样的观点layouts/partials/_footer。尝试将路径改为这样(使用点而不是斜杠):

'bind_js_vars_to_this_view' => 'layouts.partials._footer',

这应该可以解决你的问题。

答案 1 :(得分:0)

固定。它最终成为config.php文件中设置的权限问题。