标签:lumen

浏览模式: 标准 | 列表 | 图文
Lumen启动时出现:NotFoundHttpException

Lumen启动时出现:NotFoundHttpException

Lumen在初次安装好启动的时候,访问会出现:NotFoundHttpException

找了一下原因,在stackoverflow上有很多人提出来。常见的有这两种:在public/index.php里修改最后的$app->run();

  1. $app->run($app->make('request'));
  2. $app->run(Illuminate\Http\Request::capture());
如果用第1种,那你会发现所有的路由都被"/"解析了。你随便在URL里输入啥,都只会进入$app->get("/")这个路由
只有第二种才是正确的。
记录一下,参考 :
1、http://stackoverflow.com/questions/29728973/notfoundhttpexception-with-lumen
2、http://stackoverflow.com/questions/36436967/just-installed-lumen-and-got-notfoundhttpexception
Mac PHP7 Lumen Event冲突

Mac PHP7 Lumen Event冲突

在使用Lumen进行开发的时候。如果你使用:./artisan的时候报错:Cannot declare class Event, because the name is already in use。检查一下LOG发现是:

[2016-12-07 15:27:37] lumen.ERROR: ErrorException: Cannot declare class Event, because the name is already in use in /home/web/vendor/laravel/lumen-framework/src/Application.php:661
Stack trace:
#0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'Cannot declare ...', '/Volumes/docume...', 661, Array)
#1 /home/web/vendor/laravel/lumen-framework/src/Application.php(661): class_alias('Illuminate\\Supp...', 'Event')
#2 /home/web/vendor/laravel/lumen-framework/src/Application.php(631): Laravel\Lumen\Application->withAliases(Array)
#3 /home/web/vendor/laravel/lumen-framework/src/Application.php(766): Laravel\Lumen\Application->withFacades(true)
#4 /home/web/vendor/laravel/lumen-framework/src/Console/Kernel.php(54): Laravel\Lumen\Application->prepareForConsoleCommand(true)
#5 [internal function]: Laravel\Lumen\Console\Kernel->__construct(Object(Laravel\Lumen\Application))
#6 /home/web/vendor/illuminate/container/Container.php(794): ReflectionClass->newInstanceArgs(Array)
#7 /home/web/vendor/illuminate/container/Container.php(644): Illuminate\Container\Container->build('App\\Console\\Ker...', Array)
#8 /home/web/vendor/laravel/lumen-framework/src/Application.php(211): Illuminate\Container\Container->make('App\\Console\\Ker...', Array)
#9 /home/web/vendor/illuminate/container/Container.php(231): Laravel\Lumen\Application->make('App\\Console\\Ker...', Array)
#10 /home/web/vendor/illuminate/container/Container.php(746): Illuminate\Container\Container->Illuminate\Container\{closure}(Object(Laravel\Lumen\Application), Array)
#11 /home/web/vendor/illuminate/container/Container.php(644): Illuminate\Container\Container->build(Object(Closure), Array)
#12 /home/web/vendor/laravel/lumen-framework/src/Application.php(211): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#13 /home/web/artisan(32): Laravel\Lumen\Application->make('Illuminate\\Cont...')
#14 {main}

看了一下,Application.php的第661行对应的方法,我靠。

/**
* Register the aliases for the application.
*
* @param array $userAliases
* @return void
*/
public function withAliases($userAliases = [])
{
$defaults = [
'Illuminate\Support\Facades\Auth' => 'Auth',
'Illuminate\Support\Facades\Cache' => 'Cache',
'Illuminate\Support\Facades\DB' => 'DB',
'Illuminate\Support\Facades\Event' => 'Events',
'Illuminate\Support\Facades\Gate' => 'Gate',
'Illuminate\Support\Facades\Log' => 'Log',
'Illuminate\Support\Facades\Queue' => 'Queue',
'Illuminate\Support\Facades\Schema' => 'Schema',
'Illuminate\Support\Facades\URL' => 'URL',
'Illuminate\Support\Facades\Validator' => 'Validator',
];

if (! static::$aliasesRegistered) {
static::$aliasesRegistered = true;

$merged = array_merge($defaults, $userAliases);
foreach ($merged as $original => $alias) {
class_alias($original, $alias);
}
}
}

。。。。。怎么可以这样写呢?也不担心代码会不会冲突。就直接这样了??怪不得很多代码识别不了。更痛苦的是,前段时间为了测试命令行下的多线程,加载了:brew install php70-event,直接就冲突了。

不得已,brew remove php70-event。反正这个我也几乎用不到。哎~

所幸,搞定