【发布时间】:2015-11-24 21:42:54
【问题描述】:
几周前,我在 Laravel 5.1 中遇到了同样的问题,我可以通过 this solution 解决。
但是,现在我在 Lumen 中遇到了同样的问题,但我无法调用 php artisan view:clear 来清除缓存的文件。还有其他方法吗?
谢谢!
【问题讨论】:
标签: laravel laravel-artisan lumen
几周前,我在 Laravel 5.1 中遇到了同样的问题,我可以通过 this solution 解决。
但是,现在我在 Lumen 中遇到了同样的问题,但我无法调用 php artisan view:clear 来清除缓存的文件。还有其他方法吗?
谢谢!
【问题讨论】:
标签: laravel laravel-artisan lumen
lumen 中没有用于视图缓存的命令,但您可以轻松创建自己的或使用答案末尾找到的我的迷你包。
首先,将此文件放入您的 app/Console/Commands 文件夹中(如果您的应用与 App 不同,请确保更改命名空间):
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ClearViewCache extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'view:clear';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all compiled view files.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$cachedViews = storage_path('/framework/views/');
$files = glob($cachedViews.'*');
foreach($files as $file) {
if(is_file($file)) {
@unlink($file);
}
}
}
}
然后打开app/Console/Kernel.php 并将命令放入$commands 数组中(再次注意命名空间):
protected $commands = [
'App\Console\Commands\ClearViewCache'
];
您可以通过运行验证一切正常
php artisan
在项目的根目录中。
您现在将看到新创建的命令:
你现在可以像在 laravel 中一样运行它了。
编辑
我为此创建了一个小型 (MIT) package,您可以通过 composer 要求它:
composer require baao/clear-view-cache
然后添加
$app->register('Baao\ClearViewCache\ClearViewCacheServiceProvider');
到bootsrap/app.php 并使用
php artisan view:clear
【讨论】:
public function register() { $this->app['command.view.clear'] = function () { return new ClearViewCache(); }; }
view:cache 怎么样?