1. Go to this page and download the library: Download windwalker/view library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
windwalker / view example snippets
php
use Windwalker\View\AbstractView;
class MyView extends AbstractView
{
public function render()
{
$tmpl = <<<TMPL
# The is a Markdown Article
Hello %s~~~!
TMPL;
return MyMarkdown::render(sprintf($tmpl, $this->data['foo']));
}
}
// Create view and set data
$view = new MyView;
$view->set('foo', 'World');
$view->render();
php
use Windwalker\View\SimpleHtmlView;
class MyHtmlView extends SimpleHtmlView
{
public function prepare($data)
{
// Format dome data
$data['time'] = $data['time']->format('Y-m-d H:i:s');
$data['link'] = '/flower/' . OutputFilter::stringUrlSafe($data['name']) . '.html';
}
}
$view = new MyHtmlView;
$view->set('time', new DateTime);
$view->set('name', $name);
$view->setLayout('/path/to/template.php')->render();
php
$time = $data['time'];
php
use Windwalker\View\HtmlView;
$paths = new SplPriorityQueue;
$paths->insert('path/of/system', 300);
$paths->insert('path/of/theme', 500);
$data = array(
'time' => new DateTime
);
$view = new HtmlView($data, new PhpRenderer($paths));
$view->setLayout('foo')->render(); // Will find foo.php in every paths.
php
use Windwalker\View\HtmlView;
use Windwalker\Renderer\BladeRenderer;
// A Blade View
class BladeHtmlView extends HtmlView
{
public function __construct($data = array(), BladeRenderer $renderer = null)
{
$renderer = $renderer ? : new BladeRenderer('default/path', array('cache_path' => 'cache/path'))
parent::__construct($data, $renderer);
}
}
// View for different MVC structures
class ArticleHtmlView extends BladeHtmlView
{
public function prepare($data)
{
$data['time'] = $data['time']->format('Y-m-d H:i:s');
}
}
$view = new MyHtmlView;
$view->['time'] = new DateTime; // Use array access
$view->setLayout('template')->render(); // Will find template.blade.php
php
$time = $data['time']; // Exists
$name = $data['name']; // Not exists, just return null.
$title = $data->title; // Also support object access.
php
$view = new JsonView;
$view['foo.bar'] = 'baz';
$view->render();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.