问题描述
我想尝试解决一个有趣的问题. Laravel具有内置的维护模式",可以通过在应用程序的根文件夹中调用php artisan down
来激活它. app/start/global.php中有一个设置,您可以在其中分配视图或做出的响应.在我的应用程序中,我这样做:
I've got an interesting problem I'd like to try and solve. Laravel has a built in "Maintenance Mode", which can be activated by calling php artisan down
in the root folder of the application. There's a setting in app/start/global.php where you can assign the view or response it makes. In my application, I have it doing this:
App::down(function()
{
// ETA Format: YYYY-MM-DD HH-MM-SS. Leave as "" to pass indeterminate time.
return View::make("maintenance", array("code" => 503,
"message" => "Service Unavailable",
"eta" => "2014-11-07 13:30:00"));
});
这是显示一个干净整洁的我们马上回来"屏幕,其中显示状态消息和估计的完成时间.请注意,我已经硬编码了一些传递给视图的参数:
What this does is show a nice, clean "We'll be right back" screen, with the status message and estimated time to completion shown. Notice that I've hardcoded some parameters that get passed to the view:
code -> The http status code I want displayed
message -> A message about the nature of the disruption
eta -> A timestamp of the estimated completion time
我想知道的是,有什么方法可以修改php artisan down
并在其中传递一些参数吗?例如,我想尝试这样的事情:
What I'm wondering is, is there a way I can modify php artisan down
where I can pass it some parameters? For example, I want to try something like this:
php artisan down --eta="2014-11-07 13:30:00" --code="503"
因此,我不必每次将应用程序置于维护模式时都手动编码这些参数.我已经阅读过Laravel上有关创建工匠命令的文档,但是没有有关修改现有命令,复制它们以及添加功能的文档.
So I don't have to manually code these parameters everytime I put the app into maintenance mode. I've read the docs on Laravel regarding creating artisan commands, but there's no documentation on modifying existing commands, or duplicating them and adding functionality.
如果有人对此有任何见解,请告诉我.
If anyone has any insight into this, please let me know.
推荐答案
尝试创建一个您将要调用的新命令(例如app:down),将这些选项写入文件,然后在内部调用laravel down命令,例如
Try creating a new command that you would call (app:down for example) that writes those options to a file, then calls the laravel down command internally e.g.
public function fire() {
$data = json_encode($this->option());
file_put_contents('/tmp/down.txt', $data);
$this->call('down');
}
然后您可以在查看代码中找到这些内容...
Then you can pick those up in the view code...
$data = json_decode(file_get_contents('/tmp/down.txt'), true);
return View::make('maintenance', $data);
这篇关于Laravel-将参数传递给php artisan down的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!