laravel 在路由内使用 $app 错误未定义变量:app [英] laravel use $app inside routes error Undefined variable: app

查看:73
本文介绍了laravel 在路由内使用 $app 错误未定义变量:app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

laravel 5.2 文档在 路由部分.我不能在路由中使用 $app ,它会抛出以下异常:

laravel 5.2 documentation has used $app->get(..) in routing section. i cant use $app inside routes , it throw below exception:

ErrorException in routes.php line 15:

Undefined variable: app

推荐答案

Laravel 中没有 $app 这样的全局变量.您可能指的是 Lumen.

There is no such global variable as $app in Laravel. You are probably referring to Lumen.

www.laravel.com 上的 Laravel 框架与 www.lumen.laravel.com 上的 Lumen 框架不同

Laravel framework at www.laravel.com is different from Lumen framework at www.lumen.laravel.com

Lumen 是 Laravel 的瘦身版"

Lumen is 'slim down' version of Laravel

如果您尝试在 Laravel 中注册路由,则可以这样做.

If you are trying to register a route in Laravel this will do.

Route::get('/', function () { return 'Hello World'; });

想使用变量吗?试试

$router->get('/', function () { return 'Hello World'; });

如果您有兴趣访问不用于路由的应用程序,请尝试

If you are interested in accessing app, which is not used for routing, try

 $app = app();

这篇关于laravel 在路由内使用 $app 错误未定义变量:app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆