Laravel 5.1-调用未定义的方法Illuminate \ View \ Compilers \ BladeCompiler :: createPlainMatcher() [英] Laravel 5.1 - Call to undefined method Illuminate\View\Compilers\BladeCompiler::createPlainMatcher()
问题描述
尝试将我的项目从L5升级到L5.1,这是不兼容的:
Trying to upgrade my project from L5 to L5.1 and here is incompatibility:
调用未定义的方法 照亮\ View \ Compilers \ BladeCompiler :: createPlainMatcher()
Call to undefined method Illuminate\View\Compilers\BladeCompiler::createPlainMatcher()
以下是导致异常的代码:
Here's the code which cause an exception:
Blade::extend(function($view, $compiler) {
$pattern = $compiler->createPlainMatcher('spaceless');
return preg_replace($pattern, '$1<?php ob_start(); ?>$2', $view);
});
Blade::extend(function($view, $compiler) {
$pattern = $compiler->createPlainMatcher('endspaceless');
return preg_replace($pattern, '$1<?php echo trim(preg_replace(\'/>\s+</\', \'><\', ob_get_clean())); ?>$2', $view);
});
要使此代码在Laravel 5.1中正常工作,我应该更改什么?
What should I change to make this code working in Laravel 5.1?
推荐答案
我遇到了同样的问题.我调查了@lukasgeiter注释,它确实起作用,并且我将继续使用它.他指的是将刀片指令调用添加到AppServiceProvider
.
I had the same problem. I looked into @lukasgeiter comment and that does work, and I will use that going forward. He is referring to adding a blade directive call to AppServiceProvider
.
public function boot()
{
Blade::directive('datetime', function($expression) {
return "<?php echo with{$expression}->format('m/d/Y H:i'); ?>";
});
}
我已经为Laravel 5.0应用程序创建了刀片特定的服务提供商,并且有一些我不想重写的自定义功能,所以我添加了
I had created a blade specific service provider for my Laravel 5.0 app and have a few custom functions that I didn't want to rewrite so I added the createOpenMatcher
function my custom BladeServiceProvider.
就我而言,我是这样添加的.
In my case I added it like so.
<?php namespace App\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;
class BladeServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Blade::extend(function($view, $compiler) {
$pattern = $this->createOpenMatcher('spaceless');
return preg_replace($pattern, '$1<?php ob_start(); ?>$2', $view);
});
Blade::extend(function($view, $compiler) {
$pattern = $this->createOpenMatcher('endspaceless');
return preg_replace($pattern, '$1<?php echo trim(preg_replace(\'/>\s+</\', \'><\', ob_get_clean())); ?>$2', $view);
});
}
public function createOpenMatcher($function){
return '/(?<!\w)(\s*)@'.$function.'\(\s*(.*)\)/';
}
}
希望这会有所帮助!
这篇关于Laravel 5.1-调用未定义的方法Illuminate \ View \ Compilers \ BladeCompiler :: createPlainMatcher()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!