ingeniasoftware / luthier-ci

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
https://luthier.ingenia.me/ci/en/
MIT License
150 stars 38 forks source link

Philo\Blade\Blade is not working with DebugBar #26

Closed Ihabafia closed 5 years ago

Ihabafia commented 5 years ago

Hi,

It's definitely, one of the best packages for CodeIgniter if not the best. The only problem, I am facing is that the Debug Bar works perfectly with the (Intro Page), but not with my xxx.blade.php. I am using the package Philo\Blade\Blade which is great and the closest to Laravel Blade. The only thing is that the rendering page is called through echo $blade->view()->make($view, $data)->render() which it doesn't go throw the ->load->view() class.

The thing is I do use codeigniter-forensics and it worked just fine. So I am confused.

The Intro page works just fine, the regular pages does show the js and css injected it, but not the code of the bar itself.

Thank you,

Ihabafia commented 5 years ago

I checked it again and again, When I use$this->load->view() it works but when I use echo $blade->view()->make()->render(); doesn't :(

andersonsalas commented 5 years ago

Hi!

Luthier CI uses the internal output class (the Output Library). That means what you must append the content to the final output instead of being doing echo or print() in order to inject all PHP Debug Bar dependencies to that output string at the display_override framework hook point.

This is a stub of how you can archieve it, a small library that adds the Blade template result to the output (not tested yet):

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

use Philo\Blade\Blade as PhiloBlade;

class Blade
{

    /**
     * Renders a template
     */
    public function render($template, $vars = [], $return = false)
    {
        $blade = new PhiloBlade(...);

        ob_start();
        echo $blade->view()->make(...)->render();
        $templateOutput = ob_get_clean();

        if($return === true)
        {
            return $templateOutput;
        }
        else
        {
            ci()->output->append_output($templateOutput);
        }

    }
}

And in your controllers:

$this->load->library('blade');
$this->blade->render('foo', [ 'bar' => 'baz']);
Ihabafia commented 5 years ago

Perfice. It works like never been before ;)