-
-
Save otengkwame/e3219713106cf086972893d267deffd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$config['views_paths'] = array( | |
APPPATH . 'views/' | |
); | |
$config['cache_path'] = APPPATH . 'cache/blade/'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Home extends CI_Controller { | |
public function index() | |
{ | |
// Prepare some test data for our views | |
$array = explode('-', date('d-m-Y')); | |
list($d, $m, $y) = $array; | |
// Basic view with no data | |
echo $this->load->blade('home.index'); | |
// Passing a single value | |
echo $this->load->blade('home.index')->with('day', $d); | |
// Multiple values with method chaining | |
echo $this->load->blade('home.index') | |
->with('day', $d) | |
->with('month', $m) | |
->with('year', $y); | |
// Passing an array | |
echo $this->load->blade('home.index', array( | |
'day' => $d, | |
'month' => $m, | |
'year' => $y | |
)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Home extends CI_Controller { | |
public function index() | |
{ | |
// Load the view into a variable | |
$view = $this->load->blade('home.index'); | |
// Attach some data | |
$view->with('time', date('H:i:s')); | |
// Render the parsed view | |
echo $view->get(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
require 'vendor/autoload.php'; | |
use Illuminate\View; | |
use Illuminate\Events; | |
use Illuminate\Filesystem; | |
class MY_Loader extends CI_Loader { | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
public function blade($view, array $parameters = array()) | |
{ | |
$CI =& get_instance(); | |
$CI->config->load('blade', true); | |
// Get paths from configuration | |
$viewsPaths = $CI->config->item('views_paths', 'blade'); | |
$cachePath = $CI->config->item('cache_path', 'blade'); | |
// Create the file system objects | |
$fileSystem = new Filesystem\Filesystem(); | |
$fileFinder = new View\FileViewFinder($fileSystem, $viewsPaths); | |
// Create the Blade engine and register it | |
$bladeEngine = new View\Engines\CompilerEngine( | |
new View\Compilers\BladeCompiler($fileSystem, $cachePath) | |
); | |
$engineResolver = new View\Engines\EngineResolver(); | |
$engineResolver->register('blade', function() use ($bladeEngine) { | |
return $bladeEngine; | |
}); | |
// Create the environment object | |
$environment = new View\Environment( | |
$engineResolver, | |
$fileFinder, | |
new Events\Dispatcher() | |
); | |
// Create the view | |
return new View\View( | |
$environment, | |
$bladeEngine, | |
$view, | |
$fileFinder->find($view), | |
$parameters | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This updated method fixes block comments with a newline | |
// char immediately after the opening {{-- tag. | |
protected function compileComments($value) | |
{ | |
$value = preg_replace('/\{\{--(.*?)--\}\}/', "", $value); | |
return preg_replace('/\{\{--(\n?)(.*?)--\}\}/s', "$1", $value); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"illuminate/view": "4.0.x" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Home extends CI_Controller { | |
public function index() | |
{ | |
// Prepare some test data for our views | |
$array = explode('-', date('d-m-Y')); | |
list($d, $m, $y) = $array; | |
// Basic view with no data | |
echo $this->load->blade('home.index'); | |
// Passing a single value | |
echo $this->load->blade('home.index')->with('day', $d); | |
// Multiple values with method chaining | |
echo $this->load->blade('home.index') | |
->with('day', $d) | |
->with('month', $m) | |
->with('year', $y); | |
// Passing an array | |
echo $this->load->blade('home.index', array( | |
'day' => $d, | |
'month' => $m, | |
'year' => $y | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment