添加测试模板渲染的代码

deploy
caiyuzheng 2019-08-21 15:34:08 +08:00
parent 91979cf0b6
commit 48df7d1e47
4 changed files with 3 additions and 8 deletions

View File

@ -31,7 +31,7 @@ class Home extends \Core\Controller
}
public function renderAction() {
View::renderTemplate("/Home/index.html",[]);
}
public function docsAction(){
$docs = new Models\Doc();

View File

@ -4,6 +4,6 @@
{% block body %}
<h5>dfsd</h5>
<h5>this is a title</h5>
{% endblock %}

View File

@ -5,6 +5,7 @@
<title>{% block title %}{% endblock %}</title>
</head>
<body>
shit!
{% block body %}
{% endblock %}
</body>

View File

@ -9,7 +9,6 @@ namespace Core;
*/
class View
{
/**
* Render a view file
*
@ -21,16 +20,13 @@ class View
public static function render($view, $args = [])
{
extract($args, EXTR_SKIP);
$file = dirname(__DIR__) . "/App/Views/$view"; // relative to Core directory
if (is_readable($file)) {
require $file;
} else {
throw new \Exception("$file not found");
}
}
/**
* Render a view template using Twig
*
@ -42,12 +38,10 @@ class View
public static function renderTemplate($template, $args = [])
{
static $twig = null;
if ($twig === null) {
$loader = new \Twig_Loader_Filesystem(dirname(__DIR__) . '/App/Views');
$twig = new \Twig_Environment($loader);
}
echo $twig->render($template, $args);
}
}