This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
doc/book/application-integration Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ # Stand-Alone
2+
3+ The view and all view-helpers of zend-view can also be used stand-alone.
4+
5+ ## The View
6+
7+ ### Setup
8+
9+ [ Create the a renderer, set a resolver for templates] ( ../php-renderer.md#usage )
10+ and initialize the view, e.g. ` public/index.php ` :
11+
12+ ``` php
13+ // Create template resolver
14+ $templateResolver = new Zend\View\Resolver\TemplatePathStack(
15+ [
16+ 'script_paths' => [__DIR__ . '/../view'],
17+ ]
18+ );
19+
20+ // Create the renderer
21+ $phpRenderer = new Zend\View\Renderer\PhpRenderer();
22+ $phpRenderer->setResolver($templateResolver);
23+
24+ // Initialize the view
25+ $view = new Zend\View\View();
26+ $view->getEventManager()->attach(
27+ Zend\View\ViewEvent::EVENT_RENDERER,
28+ function () use ($phpRenderer) {
29+ return $phpRenderer;
30+ }
31+ );
32+ ```
33+
34+ ### Create View Script
35+
36+ [ Create a view script] ( ../view-scripts.md ) , e.g. ` view/index.phtml ` :
37+
38+ ``` php
39+ <h1 ><?= $headline ?></h1 >
40+ ```
41+
42+ ### Create View Model and render Output
43+
44+ Extend the script in ` public/index.php ` , add a view model and render the output:
45+
46+ ``` php
47+ // Create view model
48+ $viewModel = new ViewModel(['headline' => 'Example']);
49+ $viewModel->setTemplate('index.phtml');
50+
51+ // Render
52+ echo $view->render($viewModel); // <h1 >Example</h1 >
53+ ```
54+
55+ ## View Helpers
56+
57+ ### Setup
58+
59+ Create the renderer:
60+
61+ ``` php
62+ $renderer = new Zend\View\Renderer\PhpRenderer();
63+ ```
64+
65+ ### Using Helper
66+
67+ ``` php
68+ echo $renderer->doctype(Zend\View\Helper\Doctype::HTML5); // <!DOCTYPE html>
69+ ```
Original file line number Diff line number Diff line change 3030 - Placeholder : helpers/placeholder.md
3131 - Url : helpers/url.md
3232 - " Advanced usage of helpers " : helpers/advanced-usage.md
33+ - " Application Integration " :
34+ - " Stand-Alone " : application-integration/stand-alone.md
3335site_name : zend-view
3436site_description : zend-view
3537repo_url : ' https://github.com/zendframework/zend-view'
You can’t perform that action at this time.
0 commit comments