【问题标题】:Laravel 4, convert Blade syntax to PHPLaravel 4,将 Blade 语法转换为 PHP
【发布时间】:2013-04-10 19:26:50
【问题描述】:

我想知道什么是等价的:

@include('sidebars.pages')

在普通 PHP 中?

我试过这样的事情:

<?php echo view('sidebars.pages'); ?>
<?php echo view('sidebars.pages')->render(); ?>
<?php echo render('sidebars.pages'); ?>
<?php Blade::compile_string("@include('sidebars.pages')"); ?>

感谢您的帮助!

【问题讨论】:

    标签: laravel blade


    【解决方案1】:

    我知道这已经得到了回答,但以下内容是否也有效?

    <?php include 'app/views/yourview.php'; ?>
    

    【讨论】:

      【解决方案2】:

      字面意思是……

      <?php echo $__env->make('sidebar.pages', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
      

      所以在你的尝试列表中,最近的可能是

      <?php echo render('sidebar.pages', array_except(get_defined_vars(), array('__data', '__path'))); ?>
      

      参考:View\Compilers\BladeCompiler

      /**
       * Compile Blade include statements into valid PHP.
       *
       * @param  string  $value
       * @return string
       */
      protected function compileIncludes($value)
      {
          $pattern = $this->createOpenMatcher('include');
      
          $replace = '$1<?php echo $__env->make$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>';
      
          return preg_replace($pattern, $replace, $value);
      }
      
      /**
       * Get the regular expression for a generic Blade function.
       *
       * @param  string  $function
       * @return string
       */
      public function createOpenMatcher($function)
      {
          return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*)\)/';
      }
      

      【讨论】:

      • 谢谢斯帕克斯先生,我真的很好奇。
      猜你喜欢
      • 2013-12-24
      • 2017-12-24
      • 1970-01-01
      • 2018-06-15
      • 2013-11-06
      • 1970-01-01
      • 2017-06-29
      • 2016-10-22
      • 2014-02-06
      相关资源
      最近更新 更多