2013-12-22 49 views
0

我在學習Laravel。使用作曲家時,我在安裝中包含了移動偵測束(文件位於文件夾中)。當我使用的代碼在GitHub上的文檔說明Laravel:如何使用我的作曲家安裝的捆綁包?

$mobileDetector = $this->get('mobile_detect.mobile_detector');

我得到這個錯誤:

**ErrorException** 

File does not exist at path mobile_detect.mobile_detector (View:) (View:) 

我在刀片視圖中使用這一點,我想我已經設置的路徑'mobile_detect.mobile_detector',但我不知道它是什麼。也許我可以推動正確的方向?

回答

1

原因它不工作是因爲你試圖在開箱即用Laravel內使用Symfony 2包。

隨着GitHub的網頁說:

Symfony2 bundle for detect mobile devices, manage mobile view and redirect to the mobile and tablet version.

基本上,你正在嘗試運行該行是你使用裏面的Symfony服務的方式。如果您在Symfony應用程序中,但不在Laravel內,它將起作用。

// Get the mobile_detect.mobile_detector 
// service from Symfony's service container 
$mobileDetector = $this->get('mobile_detect.mobile_detector'); 

雖然可能有一些辦法讓它工作,我會在sugggest到packagist搜索一個特定Laravel包,或者PHP通用的一個,它提供了相同的功能,使您的生活更輕鬆。

我做了搜索,發現這一個,這是基於在Mobile Detect太:

+0

我有很多東西需要學習;)謝謝! –