coolpraz / php-blade

The standalone version of Laravel's Blade templating engine for use outside of Laravel.
MIT License
9 stars 1 forks source link

In codeigniter in blade view files codeigniter instance is not available like $this->session or $this->uri etc need to fix that #2

Open moazamin6 opened 4 years ago

MuhammadSaim commented 4 years ago

I also faced this issue @moazamin6 so i just did a trick just make a helper function which returns the $CI object

/**
 * get instance of CI
 */
if(!function_exists('getInstance')){
    function getInstance(){
       return $CI =& get_instance();
    }
}

and you can use this like

{{ getInstance()->session->userdata('user') }}

image image

moazamin6 commented 4 years ago

@MuhammadSaim you are write. this is great to create a helper method and call that method in views where we need $this instance. It is very good approach where start creating new application from scratch but in existing codeigniter or any other application it is very difficult to replace $this to getInstance() helper method. Because I want to integrate blade template in very big codeginter application that have near about 100 view files. So it is very expensive to edit all 100 files.

So I dig into core of illuminate/view package and make some changes. You can install the package from composer by running the following command

composer require moazamin6/creative-blade

you can also find that package on following link

GitHub: https://github.com/moazamin6/creative-blade Packagist: https://packagist.org/packages/moazamin6/creative-blade

Thanks