Skip to content

Latest commit

 

History

History
37 lines (30 loc) · 604 Bytes

isset.md

File metadata and controls

37 lines (30 loc) · 604 Bytes

isset

为了方便在模板中判断变量是否存在,Blade提供了@isset指令,用法如下:

@isset($foo)
@else
@endisset

实现如下:

//src/Illuminate/View/Compilers/Concerns/CompilesConditionals.php

/**
 * Compile the if-isset statements into valid PHP.
 *
 * @param  string  $expression
 * @return string
 */
protected function compileIsset($expression)
{
    return "<?php if(isset{$expression}): ?>";
}

/**
 * Compile the end-isset statements into valid PHP.
 *
 * @return string
 */
protected function compileEndIsset()
{
    return '<?php endif; ?>';
}