【问题标题】:Laravel FrozenNode Administrator run in maintenance modeLaravel FrozenNode Administrator 在维护模式下运行
【发布时间】:2013-07-19 23:00:34
【问题描述】:

我的问题是: 如何让 Frozennode 管理员在 Laravel 维护模式下正常运行?

这是我在 global.php 中得到的

App::down(function()
{
    return Response::view('maintenance', array(), 503);
});

谢谢!

【问题讨论】:

    标签: laravel laravel-4 administration


    【解决方案1】:

    我已经挖到了核心,你没办法做到。 Laravel 在app/storage/meta 文件夹中检查一个名为down 的文件,如果它在那里,Laravel 甚至不会调用路由,它只会显示错误页面。

    这是来自 laravel 的 isDownForMaintenance 函数:

    public function isDownForMaintenance()
    {
        return file_exists($this['path.storage'].'/meta/down');
    }
    

    无法进行配置。

    laravelish“维护模式”的另一种方法是在config/app.php中设置一个新值,添加:

    'maintenance' => true,
    

    然后将其添加到您的 before 过滤器中:

    App::before(function($request)
    {
        if(
            Config::get('app.maintenance') &&
            Request::segment(1) != 'admin' // This will work for all admin routes
            // Other exception URLs
        )
        return Response::make(View::make('hello'), 503);
    });
    

    然后设置:

    'maintenance' => true,
    

    回到正常模式

    【讨论】:

      【解决方案2】:

      实际上还有另一种方式,更直接。正如您在 Laravel documentation 中所读到的,从闭包返回 NULL 将使 Laravel 忽略特定请求:

      如果传递给 down 方法的闭包返回 NULL,则该请求将忽略维护模式。

      所以对于以 admin 开头的路由,你可以这样做:

      App::down(function()
      {
        // requests beginning with 'admin' will bypass 'down' mode
        if(Request::is('admin*')) {
          return null;
        }
      
        // all other routes: default 'down' response
        return Response::view('maintenance', array(), 503);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-18
        • 1970-01-01
        • 1970-01-01
        • 2019-03-14
        • 1970-01-01
        • 2012-04-13
        • 2022-01-27
        相关资源
        最近更新 更多