Answer the question
In order to leave comments, you need to log in
Isn't it shit?
Base view
/**
* @param $view
* @param array $params
*/
public function render($view, Array $params = NULL, $template = "main"){
\ob_start();
if ($params !== NULL) {
extract($params);
}
require_once Logic::get() . "/views/".$view.".php";
$content = \ob_get_contents();
\ob_end_clean();
require_once Logic::get() . "/views/layouts/" . $template . ".php";
}
//....
$all_cats = $this->model->getCategories();
$this->view->render("site/catalog/add",
["msg" => $this->msg,
"all_cats" => $all_cats]
);
//.....
try {
$model = $this->model->allNews();
} catch(\Exception $e) {
$this->msg = $e;
}
$this->view->render("site/news/index", ["model" => $model]);
Answer the question
In order to leave comments, you need to log in
Shitcode.
Logic::get() is not called what it does. And in any case, calling a static method is inappropriate here. You need to get a configuration instance and use it.
The existence of a file with a template is not checked.
The $params check code can be simplified.
The layout should be specified inside the internal template, and not when calling the template engine.
In its purest form, PHP is a very poor templating engine. If you want to write PHP in a template, try Blade ( https://laravel.com/docs/5.2/blade). Because if you fix the shortcomings of PHP for templating, you will end up writing its analogue.
The render function always requires two-level templating for you, so you cannot use it, for example, for templating a mail message.
Don't output the content inside the function, return it.
Better just take the Twig template engine and enjoy working with quality code.
shit d ? 2015 was a complete ge for me, yes.
logicSo what are the class names? logic. What is Logic?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question