2014-04-09 35 views
0

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

回答

0

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

0

发生这种情况是因为没有这种视图layouts/partials/_footer。试着改变你的路径是这样的(用点而不是斜杠):

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

这应该解决您的问题。

+0

我确实改变了你的建议,但仍然无效。我在本地使用反斜杠,它工作正常。 –