Codeigniter with Blade, huh?

Asked

Viewed 360 times

2

I’m starting to study CI and how I used a little Laravel to facilitate was trying to put the Blade, follow this tutorial. I followed the scratch the tutorial, but returns these mistakes:

log

How to solve these problems?

  • I couldn’t put it in the post, but I put it in the github: https://github.com/HenriqueBuzin/van

1 answer

2


The problem is change of version, the file blade.php created in the folder application\libraries shall contain the following code by configuration obtained on its own github: Xiaoler/Lade, different from what is in the tutorial as it is old and the version has been changed, example of the 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 in views should follow the nomenclature blade.php example:

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

to work.

To call command in your controller:

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

to view following the name nomenclature thus remaining: test_message.blade.php

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

inserir a descrição da imagem aqui

Observing: only the file blade.php should be modified, the rest remains the same as the tutorial.

References:

  • Hello, I modified the mentioned files, but it still has some errors, I put the folder with the images in the root of git with the name erros_images tried to do the same as explained.

  • This code has been tested and worked, but say the bugs please @henriquebuzin

  • @Henriquebuzin gave permission to write and read in the folder ??? in both inclusive. is missing this I believe. has to check if it generates the files in both folders???

  • I used chmod 777 recursive throughout the project, but it still has two major errors (I think the others derive from these): Undefined index: config no core/Loader.php and file_put_contents(/Users/henrique_buzin/Sites/van/application/cache/views/5cf6b83b721d4d7c20fd127315dc5ae3fbb5aec9.php): failed to open stream: No such file or directory no src/Filesystem.php put a png of all the errors in git in the erros_images folder: https://github.com/HenriqueBuzin/van/tree/erros_images knows what could be?

  • @Henriquebuzin I made an edit, you created the cache folder? the same is in the edition.

  • Hello, I’ve done the editing now, fixed almost everything, only one more error, I put the photo in git tb, the error is the following: Undefined index: config and Use of Undefined Constant message - assumed 'message' seems not recognizing the variable, in the end it shows the message like this: message. You know what it could be? Hug.

  • @Henriquebuzin blade.php this different from the answer copy again. Which is line s 26!?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.