php dahil simüle?

0 Cevap php

I'm trying to create a small template system and have a function that loops over an array of items. Currently I'm using the output buffering functions and include so i can load up the template file while it has scope to the class.

function loadTemplate($name, $vars) {
    $buf = '';
    $path = $name . '.html';
    if (file_exists($path)) {
        $this->vars = $vars;
        ob_start();
        include($path);
        $buf = ob_get_clean();
    }
    return $buf;
}

Ben (o dahil oldu sanki) gibi, kapsamı tutarken çalıştırmak sonra bir dizide ilk şablonu saklamak olabilir, ben sadece merak ediyordum.

function loadTemplate($name, $vars) {
    $buf = $template = '';
    if (isset($this->cache[$name]))
        $template = $this->cache[$name];
    else {
        $path = $name . '.html';
        $template = file_get_contents($path);
        $this->cache[$name] = $template;
    }
    //Exec template here with scope.
}

Yoksa ben sadece bilgiçlik ve mikro optimize çalışıyorum :)

0 Cevap