清除 Lumen 上的视图缓存
Clear views cache on Lumen
几周前,我在 Laravel 5.1 遇到了同样的问题,我可以用 解决。
但是,现在我在 Lumen 中遇到了同样的问题,但我无法调用 php artisan view:clear
来清除缓存文件。还有别的办法吗?
谢谢!
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'
];
您可以验证 运行ning
一切正常
php artisan
在项目的根目录中。
您现在将看到新创建的命令:
您现在可以 运行 就像在 laravel 时一样。
编辑
我为此创建了一个小型 (MIT) package,您可以使用 composer 要求它:
composer require baao/clear-view-cache
然后添加
$app->register('Baao\ClearViewCache\ClearViewCacheServiceProvider');
到 bootsrap/app.php
和 运行 它与
php artisan view:clear
几周前,我在 Laravel 5.1 遇到了同样的问题,我可以用
但是,现在我在 Lumen 中遇到了同样的问题,但我无法调用 php artisan view:clear
来清除缓存文件。还有别的办法吗?
谢谢!
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'
];
您可以验证 运行ning
一切正常php artisan
在项目的根目录中。
您现在将看到新创建的命令:
您现在可以 运行 就像在 laravel 时一样。
编辑
我为此创建了一个小型 (MIT) package,您可以使用 composer 要求它:
composer require baao/clear-view-cache
然后添加
$app->register('Baao\ClearViewCache\ClearViewCacheServiceProvider');
到 bootsrap/app.php
和 运行 它与
php artisan view:clear