Comments (5)
@jorgecc yes ,i know ,thank you very much . I found a solution before you publish the YAF wiki , and I make yaf templete just like laravel. here is my code:
D:\phpStudy\PHPTutorial\WWW\yaf_test\application\library\BladeCache.php
<?php
use eftec\bladeone\BladeOne;
use eftec\bladeone\BladeOneCache;
class BladeCache extends BladeOne
{
use BladeOneCache;
}
D:\phpStudy\PHPTutorial\WWW\yaf_test\application\library\BladeAdapter.php
<?php
use eftec\bladeone\BladeOne;
class BladeAdapter implements Yaf\View_Interface
{
public $_blade;
/**
* Constructor
*
* @param string $tmplPath
* @param array $extraParams
* @return void
*/
public function __construct()
{
$bladeConfig = Yaf\Registry::get("config")->get("blade")->toarray();
$views = $bladeConfig['template_dir'] ?? '';
$cache = $bladeConfig['cache_dir'] ?? '';
// 使用缓存
$this->_blade = new BladeCache($views, $cache);
// 不使用缓存
// $this->_blade = new BladeOne($views, $cache, BladeOne::MODE_AUTO);
$this->_blade->setInjectResolver(function ($className) {
// Custom logic for resolving
return new $className();
});
// 全局变量
// $this->_blade->share('lang', 'test');
foreach ($bladeConfig as $key => $value) {
$this->_blade->$key = $value;
}
}
/**
* Set the path to the templates
*
* @param string $path The directory to set as the path.
* @return void
*/
public function setScriptPath($path)
{
if (is_readable($path)) {
$this->_blade->template_dir = $path;
return;
}
throw new Exception('Invalid path provided');
}
/**
* Retrieve the current template directory
*
* @return string
*/
public function getScriptPath($request = null)
{
return $this->_blade->template_dir ?? null;
}
public function assign($name, $value = null)
{
return true;
}
public function render($view_path, $tpl_vars = null)
{
return true;
}
public function display($view_path, $tpl_vars = null)
{
echo $this->_blade->run($view_path, $tpl_vars);
}
public function getView()
{
return $this->_blade;
}
}
common helper function:
function view($view_path, $tpl_vars = [])
{
$blade = new BladeAdapter();
return $blade->display($view_path, $tpl_vars);
}
then i use blade one in my app like below:
public function readAction()
{
$id = $this->getRequest()->getQuery('id');
$data = $this->article->articleInfo($id);
return view('article.read', $data);
}
application.ini
[common]
application.directory = APPLICATION_PATH "/application"
application.dispatcher.catchException = TRUE
application.view.ext=blade.php
[product : common]
blade.template_dir = APPLICATION_PATH "/application/views/"
blade.cache_dir = APPLICATION_PATH "/application/cache/"
I directly return true in render and assign ,because I don't need the two function , and my app work well. by the way ,when we use bladeone in other unlike laravel , mostly we can set suffix of templete and the left-right quotes , so we can use plugins in code editor, just use laravel blade snippets.
thank you reply so quickly.
from bladeone.
Ok, let's me see it.
from bladeone.
Added on 3.23
from bladeone.
@jorgecc how to use share global variables in blade one ? I am using yaf framework
from bladeone.
Hi there:
Did you know that you could open a new issue?. It is for free ;-)
Anyways, here it goes:
https://github.com/EFTEC/BladeOne/wiki/Using--BladeOne-with-YAF
from bladeone.
Related Issues (20)
- Custom fatal exception view HOT 1
- BladeOne compatibility with acf_register_block_type HOT 1
- Blade directive inside any comment causes Blade to try and parse it as uncommented and crashes. HOT 2
- BladeOne::getCompiledFile's hashes should include the full template path HOT 1
- The cache directory is automatically created in v4.6, but not in v4.7 and v4.7.1.
- components included get params/vars passed from previous call if omitted HOT 1
- Small note for cleanup: Param $isParent @ runInternal is never used HOT 2
- Template stack only work when push is called before stack tag HOT 1
- Use of ngettext isn't working HOT 1
- Load all stacks with a certain prefix HOT 3
- If statements without spaces HOT 1
- State of BladeOneCacheRedis?
- ParseError in @extends
- Foreach returning error HOT 2
- Mbstring Requirement HOT 2
- @auth with multiple roles
- Documentation issue default/defaultcase
- refazer facial
- Some errors are not catched in the view evalutation process HOT 1
- Inconsistent Line Endings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bladeone.