Skip to content

Commit 7257c50

Browse files
committed
page plugin
1 parent 2a70377 commit 7257c50

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

config/route.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Mvc5\Plugin\Callback;
77
use Mvc5\Session\SessionMessages;
88
use Mvc5\Service\Context;
9+
use Plugin\Page;
910
use Plugin\Redirect;
1011
use Psr\Http\Message\ResponseInterface as Response;
1112
use Valar\RedirectResponse;
@@ -91,6 +92,10 @@
9192
'path' => '/redirect',
9293
'controller' => new Redirect('/home'),
9394
],
95+
'page' => [
96+
'path' => '/page',
97+
'controller' => new Page('home/index', ['title' => 'Demo Page']),
98+
],
9499
'app' => [
95100
/*'host' => 'nexus.app.dev',
96101
'port' => 8000,*/

src/Plugin/Page.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
*
4+
*/
5+
6+
namespace Plugin;
7+
8+
use Mvc5\Arg;
9+
use Mvc5\Http\Request;
10+
use Mvc5\Plugin\Call;
11+
use Mvc5\Plugin\Callback;
12+
13+
class Page
14+
extends Call
15+
{
16+
/**
17+
* @param string $template
18+
* @param array $vars
19+
*/
20+
function __construct(string $template, array $vars = [])
21+
{
22+
parent::__construct([$this, '__invoke'], [$template, $vars]);
23+
}
24+
25+
/**
26+
* @param string $template
27+
* @param array $vars
28+
* @return Callback
29+
*/
30+
function __invoke(string $template, array $vars)
31+
{
32+
return new Callback(function(Request $request) use($template, $vars) {
33+
return $this->plugin(Arg::VIEW_MODEL, [$template, $vars + [Arg::REQUEST => $request]]);
34+
});
35+
}
36+
}

view/home/index.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
?>
99
<div class="jumbotron">
10-
<h1><a href="<?= $this->url('home') ?>"><?= $this->title() ?></a></h1>
10+
<h1><a href="<?= $this->url('home') ?>"><?= $this->title ?></a></h1>
1111
<p class="lead"><?= $this['message'] ?></p>
1212
<pre><?= __FILE__; ?></pre>
1313
<div id="ajax-result"></div>
1414
<p>
1515
<a class="btn btn-primary btn-lg" href="#" role="button" onclick="return info();">Info</a>
1616
<a class="btn btn-primary btn-lg" href="#" role="button" onclick="return about();">About</a>
1717
<a class="btn btn-primary btn-lg" href="#" role="button" onclick="return demo();">Demo</a>
18+
<a class="btn btn-primary btn-lg" href="/page" role="button">Page</a>
1819
<a class="btn btn-primary btn-lg" href="/redirect" role="button">Redirect</a>
1920
</p>
2021
</div>

0 commit comments

Comments
 (0)