【问题标题】:Javascript namespace not defined Jeffrey Way PHP vars to JavascriptJavascript 命名空间未定义 Jeffrey Way PHP vars to Javascript
【发布时间】: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


    【解决方案1】:

    发生这种情况是因为没有这样的视图layouts/partials/_footer。尝试将路径更改为这样(使用点而不是斜线):

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

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

    【讨论】:

    • 我确实做了你建议的改变,但它仍然不起作用。我在本地有反斜杠,它工作正常。
    【解决方案2】:

    已修复。它最终成为 config.php 文件中设置的权限问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 2016-03-29
      • 2013-06-12
      • 2015-11-14
      • 2010-12-05
      • 2011-12-02
      • 2011-03-25
      相关资源
      最近更新 更多