D
D
dev4002016-04-24 17:52:38
PHP
dev400, 2016-04-24 17:52:38

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";
  }

Is it normal for a base look? In the controller we call something like this
//....
            $all_cats = $this->model->getCategories();
            $this->view->render("site/catalog/add",
                ["msg" => $this->msg,
                 "all_cats" => $all_cats]
            );
           //.....

or so
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

2 answer(s)
O
OnYourLips, 2016-04-24
@dev400

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.

T
trevoga_su, 2016-04-24
@trevoga_su

shit d ? 2015 was a complete ge for me, yes.

logic
So what are the class names? logic. What is Logic?
in the client code, you do not specify $template, but in the render method $content remains in the method's scope. and then what?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question