简体   繁体   English

它是如何完成的 - Laravel Blade 声明

[英]How it's done - Laravel Blade statements

How it is done, that we can have for example something like this in a blade view:它是如何完成的,我们可以在刀片视图中有这样的东西:

@if (count($records) === 1) 
(...)

After analyzing the bladeCompiler.php file, I can see that this is converted to PHP, there is for example a method like this:分析了bladeCompiler.php文件后,我可以看到这是转换为PHP,例如有这样的方法:

protected function compileIf($expression)
{
    return "<?php if{$expression}: ?>";
}

It is then indirectly used by "compileString" method, which takes and returns a string.然后它被“compileString”方法间接使用,该方法接受并返回一个字符串。

But what then?但是呢? I can't find an occurence of the PHP's "eval" function call in the entire project, so how it's done?我在整个项目中都找不到 PHP 的“eval”函数调用的出现,那么它是如何完成的呢?

After Blade has compiled the PHP code, Laravel puts the result into a cached file in the storage/framework/views/ directory. Blade 编译完 PHP 代码后,Laravel 将结果放入storage/framework/views/目录下的缓存文件中。 That file is then called directly, so you don't need any eval() statements.然后直接调用该文件,因此您不需要任何eval()语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM