本文整理匯總了PHP中League\Plates\Engine::loadExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP Engine::loadExtension方法的具體用法?PHP Engine::loadExtension怎麽用?PHP Engine::loadExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類League\Plates\Engine
的用法示例。
在下文中一共展示了Engine::loadExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: register
public function register()
{
$this->container->add('service.http.request', function () {
return Request::createFromGlobals();
});
$this->container->add('service.http.route', function () {
$route = new Route($this->container);
foreach ($this->container->get('config')['http']['routes'] as $item) {
$route->addRoute(strtoupper($item['method']), $item['path'], $item['target']);
}
return $route;
});
$this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () {
return $this->container->get('service.http.request');
});
$this->container->add('service.view.view', function () {
$view = new View();
foreach ($this->container->get('config')['http']['views_path'] as $name => $path) {
$view->addFolder($name, $path);
}
$request = $this->container->get('service.http.request');
$view->loadExtension(new RequestExtension($request));
$view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag()));
$view->loadExtension(new BaseUrlExtension($request->getBasePath()));
$assetBaseUrl = $this->container->get('config')['asset_base_url'];
$view->loadExtension(new AssetUrlExtension($assetBaseUrl));
if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) {
$authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser();
$view->loadExtension(new AuthenticatedUserExtension($authenticatedUser));
}
$view->addData(['applicationName' => $this->container->get('config')['application_name']]);
return $view;
});
}
示例2: plates
private function plates()
{
$league = new Plates\Engine(APP . 'views');
$league->setFileExtension('tpl');
$league->loadExtension(new Plates\Extension\URI(trim(strtok(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']), '?'), '/')));
$league->loadExtension(new MY\Plates\Extension());
return $league;
}
示例3: init
/**
* @MethodInit()
*/
public function init()
{
$this->loadDebug();
foreach ($this->plateExtensions as $extension) {
$this->templateEngine->loadExtension($extension);
}
$routes = $this->routes;
foreach ($routes as $route) {
$this->registerRoute($route);
}
}
示例4: __construct
/**
* MY_Controller constructor.
*/
public function __construct()
{
parent::__construct();
// Profiler only development environment
if (ENVIRONMENT === 'development' and $this->config->item('profiler') === TRUE) {
$this->load->add_package_path(APPPATH . 'packages/codeigniter-forensics');
$this->output->enable_profiler(TRUE);
}
// Templates
$this->template = new League\Plates\Engine(APPPATH . 'views');
$this->template->registerFunction('CI', function () {
return $this;
});
$this->template->loadExtension(new League\Plates\Extension\Asset(FCPATH));
}
示例5: __invoke
public function __invoke(array $input)
{
$name = 'index';
if (!empty($input['name'])) {
$name = $input['name'];
}
// $filename = APPPATH . 'templates/static/' . $name;
// if (file_exists($filename)) {
// echo "The file $filename does not exist";
// die('the file does not exist');
// }
// Create new Plates instance
$plates = new Engine(APPPATH . 'templates');
// Register extension
$plates->loadExtension(new Utils());
// Check static page or partial exists
if ($plates->exists('static/' . $name)) {
// Render a template
$template = $plates->render('static/' . $name);
} else {
header("HTTP/1.0 404 Not Found");
echo "PHP continues.\n";
echo "Not after a die, however.\n";
die;
}
// return
return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]);
}
示例6: register
/**
* @param Engine $engine
*/
public function register(Engine $engine)
{
// Load the built in URI extension
$engine->loadExtension(new URI($this->request->getPathInfo()));
// Custom methods
$engine->registerFunction('route', [$this, 'route']);
$engine->registerFunction('asset', [$this, 'asset']);
}
示例7: getInstance
/**
* Get an instance of the Plates Engine
*
* @return \League\Plates\Engine
*/
public function getInstance()
{
if (!$this->engineInstance) {
$this->engineInstance = new Engine($this->templatesPath ?: $this->getTemplatesDirectory());
if ($this->fileExtension) {
$this->engineInstance->setFileExtension($this->fileExtension);
}
if (count($this->templatesFolders) > 0) {
foreach ($this->templatesFolders as $name => $path) {
$this->engineInstance->addFolder($name, $path);
}
}
if (count($this->parserExtensions) > 0) {
foreach ($this->parserExtensions as $extension) {
$this->engineInstance->loadExtension($extension);
}
}
}
return $this->engineInstance;
}
示例8: dispatch
public function dispatch()
{
// strip index.php and query string (if any) to get a real base url
$baseUrl = preg_replace('/(index\\.php.*|\\?.*)$/', '', $_SERVER['REQUEST_URI']);
$templates = new Engine(CURRENT_DIR . '/src/Resources/views/');
$templates->loadExtension(new Asset(CURRENT_DIR . '/pub/', false));
$templates->loadExtension(new URI($baseUrl));
// Check if the user is logged-in
if (!$this->isLoggedIn()) {
return $this->showLogin($templates);
}
if (is_null($this->command)) {
/** @var Checkpoint $checkpoint */
$checkpoint = $this->container['utils.checkpoint'];
$checkpoints = $checkpoint->getAll();
$content = $templates->render('partials/inner', ['title' => 'Updater', 'version' => $this->container['application']->getVersion(), 'checkpoints' => $checkpoints]);
} else {
header('Content-Type: application/json');
$content = json_encode($this->ajaxAction(), JSON_UNESCAPED_SLASHES);
}
return $content;
}
示例9: create
/**
* Create instance
*
* @return Engine
*/
public function create(Request $request)
{
$engine = new Engine($this->options['view_path'], null);
// Add folder shortcut (assets::file.js)
$engine->addFolder('assets', $this->options['assets_path']);
$engine->addFolder('view', $this->options['view_path']);
$session = $request->getAttribute(SessionMiddleware::ATTRIBUTE);
$baseUrl = $request->getAttribute('base_url');
// Register Asset extension
$cacheOptions = array('cachepath' => $this->options['cache_path'], 'cachekey' => $session->get('user.locale'), 'baseurl' => $baseUrl, 'minify' => $this->options['minify']);
$engine->loadExtension(new \Odan\Plates\Extension\AssetCache($cacheOptions));
return $engine;
}
示例10: register
public function register(App $glue)
{
$glue->singleton('League\\Plates\\Engine', function ($glue) {
if (!$glue->config->exists('plates.path')) {
// We need a default template folder
throw new \Exception("You must configure the plates.path");
}
$engine = new Engine($glue->config->get('plates.path'));
// Register some extensions
$engine->loadExtension($glue->make('Glue\\Plates\\Extensions\\UrlHelpers'));
return $engine;
});
$glue->alias('League\\Plates\\Engine', 'plates');
}
示例11: __invoke
public function __invoke(array $input)
{
$name = 'world';
if (!empty($input['name'])) {
$name = $input['name'];
}
////////////////////
$application = new Application();
$application_data = $application->is_pjax();
//print_r( '<pre>' );
// print_r( $application_data );
//print_r( '</pre>');
////////////////////
// simple
// Create new Plates instance
// $plates = new Engine(APPPATH.'templates');
// Render a template
// $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]);
// $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]);
$data = ['friends' => ['mikka', 'makka', 'zorro']];
// $friends = [
// ['name', 'zorro'],
// ];
////////////////////
// using folders
// Create new Plates instance
$plates = new Engine(APPPATH . 'templates');
// Register a Plates extension
$plates->loadExtension(new Utils());
// Add folders
$plates->addFolder('layout', APPPATH . 'templates');
$plates->addFolder('partials', APPPATH . 'templates/partials');
$plates->addFolder('static', APPPATH . 'templates/static');
// assign data to plates
$plates->addData($data, 'layout');
// Render
$template = $plates->render('partials::profile', ['name' => $name]);
////////////////////
$invitation = 'I invite you';
// return
return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]);
}
示例12: prepareTemplates
public function prepareTemplates(Engine $template, Injector $injector)
{
$template->addData(['pages' => $this->getPages()]);
$template->setFileExtension('phtml');
$template->loadExtension(new DirectoryExtension());
}
示例13: setAssetPath
/**
* Set Asset path from Plates Asset Extension.
*
* @param string $assetPath
*
* @return \League\Plates\Engine
*/
public function setAssetPath($assetPath)
{
return $this->plates->loadExtension(new Asset($assetPath, $this->settings['timestampInFilename']));
}
示例14: setAssetPath
/**
* Set Asset path from Plates Asset Extension
*
* @param string $assetPath
*/
public function setAssetPath($assetPath)
{
return $this->plates->loadExtension(new Asset($assetPath));
}
示例15: initViewCache
/**
* Init view assets cache
*
* @return void
*/
protected static function initViewCache(Engine $view, ServiceContainer $app)
{
// Register Asset extension
$options = array('cachepath' => $app->config['path']['view_cache'], 'cachekey' => $app->session->get('locale'), 'baseurl' => $app->http->getBaseUrl('/'), 'minify' => $app->config['view']['minify']);
$view->loadExtension(new \Odan\Plates\Extension\AssetCache($options));
}