laravel-4:如何找到NotFoundHttpException的路由?

时间:2013-11-26 14:04:29

标签: php laravel-4

我在日志中发现了NotFoundHttpException。它看起来像这样:

[2013-11-26 13:49:20] log.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /var/www/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1429
Stack trace:
#0 /var/www/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1050): Illuminate\Routing\Router->handleRoutingException(Object(Symfony\Component\Routing\Exception\ResourceNotFoundException))
#1 /var/www/myproject/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1014): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 /var/www/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(530): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#3 /var/www/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(506): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#4 /var/www/myproject/public/index.php(49): Illuminate\Foundation\Application->run()
#5 {main} [] []

这告诉你什么,只是浪费磁盘空间。

如何找到导致NotFoundHttpException的URI?

2 个答案:

答案 0 :(得分:36)

{p} app/start/global.php App::error()中的

App::error(function(Exception $exception, $code)
{
    if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
    {
        Log::error('NotFoundHttpException Route: ' . Request::url() );
    }

    Log::error($exception);
});

现在您将获得一个包含URL的其他日志条目:

 [2013-11-26 14:20:07] log.ERROR: NotFoundHttpException Route: http://myproject.net/asdfgsdfghsdfg [] []

答案 1 :(得分:1)

您可以从日志文件中过滤404(NotFoundHttpException)错误。
文件位置:app / start / global.php

import React from 'react';
import { Route } from 'react-router';
import configureStore from './store/configureStore';

import { loadAllContent, loadSpecificContent } from './actions/myContentActions';
import { loadMetadata } from './actions/metadataActions';

import App from './components/App';
import MyContentPage from './components/MyContent/MyContentPage';
import ManageContentPage from './components/MyContent/ManageContentPage';

export const store = configureStore();

export const routes = (
  <Route path={'/'} component={App}>
    // This page works fine as only one dispatch
    <Route
      path={'/my-content'}
      component={MyContentPage}
      onEnter={() => store.dispatch(loadAllContent())}
    />
    // This page fires the first function fine but not the second
    <Route
      path={'/my-content/:id'}
      component={ManageContentPage}
      // dispatch multiple actions here
      onEnter={() => store.dispatch(loadSpecificContent(), loadMetadata('ages'))}
    />
  </Route>
);