Laravel:如何使用我的作曲家安装捆绑?

时间:2013-12-22 09:39:59

标签: php laravel composer-php

我正在学习Laravel。使用composer i在安装中包含了mobile-detect-bundle(文件在文件夹中)。当我使用github上的文档中所述的代码时

$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 个答案:

答案 0 :(得分:1)

无法正常工作的原因是因为您正试图在Laravel内部使用Symfony 2捆绑包

正如github页面所说:

  

Symfony2捆绑包,用于检测移动设备,管理移动视图并重定向到移动设备和平板电脑版本。

基本上,您尝试运行的行是您在Symfony中使用服务的方式。如果你在Symfony应用程序中,它将工作,但不在Laravel内。

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

虽然可能有某种方法可以使它工作,但我建议在packagist中搜索Laravel特定包,或者提供相同功能的PHP通用包,以使您的生活更轻松。

我已经进行了搜索并找到了这个,它也基于Mobile Detect