CodeIgniter with Blade?

1

I'm starting to study CI and how I used a little Laravel to facilitate I was trying to put Blade , I followed this tutorial . I followed the tutorial, but it returns those errors :

  

How to solve these problems?

    
asked by anonymous 18.07.2017 / 03:08

1 answer

2

The problem is version change , the blade.php file created in the application\libraries folder must contain the following code, using configuration obtained in its own github: XiaoLer / blade , different from what is in the tutorial, because it is old and the version has changed, example of changes:

<?php defined('BASEPATH') or exit('No direct script access allowed');
class Blade
{
    private $factory;
    public function __construct()
    {        
        $path = [APPPATH . 'views/'];
        $cachePath = APPPATH . 'cache/views';        
        $file = new \Xiaoler\Blade\Filesystem;
        $compiler = new \Xiaoler\Blade\Compilers\BladeCompiler($file, $cachePath);       
        $compiler->directive('datetime', function($timestamp) {
            return preg_replace('/(\(\d+\))/', 
                    '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
        });
        $compiler->directive('now_datetime', function() {
            return '<?php echo date("Y-m-d H:i:s", '.(strtotime('now')).'); ?>';
        });        
        $resolver = new \Xiaoler\Blade\Engines\EngineResolver;
        $resolver->register('blade', function () use ($compiler) {
            return new \Xiaoler\Blade\Engines\CompilerEngine($compiler);
        });
        $this->factory = new \Xiaoler\Blade\Factory($resolver, 
                            new \Xiaoler\Blade\FileViewFinder($file, $path));
        $this->factory->addExtension('tpl', 'blade');
    }    
    public function view($path, $vars = [])
    {
        echo $this->factory->make($path, $vars);
    }
    public function exists($path)
    {
        return $this->factory->exists($path);
    }
    public function share($key, $value)
    {
        return $this->factory->share($key, $value);
    }
    public function render($path, $vars = [])
    {
        return $this->factory->make($path, $vars)->render();
    }

}

and the views created must follow the% nomenclature blade.php example:

  • index.blade.php
  • home.blade.php

to work.

To call the command in its controller :

class Welcome extends CI_Controller 
{
    public function test()
    {
        $data['message'] = 'message 1';
        $this->blade->view('test_message', $data);
    }
}

a view following the name nomenclature thus: test_message.blade.php

Another point to note is the creation of the application\cache\views cache folder, as an example of the figure below:

Note:Onlythefileblade.phpshouldbemodified,therestremainsthesameasthetutorial.

18.07.2017 / 04:24