jst*_*ios 4 php class vendor laravel laravel-4
我想在m routes.php文件中使用Mobile Detect.我在composer.json中添加了包作为require,并将其安装在供应商文件中.我现在该怎么用?
我尝试了这个答案并且没有运气,因为没有找到类:Laravel 4使用供应商类
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"mobiledetect/mobiledetectlib": "*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
Run Code Online (Sandbox Code Playgroud)
编辑:我尝试使用这个:https://github.com/jenssegers/Laravel-Agent,但别名从来没有说过没有找到类.
该包是PSR-0命名空间.看看git repo,似乎Detection\MobileDetect 你会想确保这确实是正确的命名空间.您是否尝试在routes.php文件中添加适当的命名空间?
use Detection\MobileDetect as MobileDetect;
Run Code Online (Sandbox Code Playgroud)
或者您可以引用正确的内联命名空间.这是一个例子:
$detect = new Detection\MobileDetect\Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
Run Code Online (Sandbox Code Playgroud)
如果这对您不起作用,您可以通过将其添加到您的composer.json类图中来逃脱:
"autoload": {
"classmap": ["/vendor/serbanghita/namespaced/"],
}
Run Code Online (Sandbox Code Playgroud)
当然,填写正确的路径然后运行一个composer dump-auto.
| 归档时间: |
|
| 查看次数: |
17997 次 |
| 最近记录: |