2014-04-09 49 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

我確實改變了你的建議,但仍然無效。我在本地使用反斜槓,它工作正常。 –