Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    cosa è new Template???

    Salve premetto che non ho mai lavorato in PHP, la mia esperienza è tutta su Asp.

    Mi ritrovo ora a dover modificare un sito già relaizzato in php

    in una pagina ho trovato il seguente codice:

    <?php
    include "includeF/template.inc";

    $main=new Template("index.htm");
    $main->setContent(esito,"");
    $main->parse();
    $main->close();
    break;




    VVoVe: VVoVe:
    Qualcuno può dirmi a cosa serve questo codice????



    nel file template.inc che viene incluso c'è il seguente codice:
    <?

    class Template {
    var $template_file,
    $buffer,
    $foreach,
    $content,
    $debug;

    function Template($filename,$debug = "") {
    $this->template_file = $filename;
    $this->debug = $debug;
    $fp = fopen ($filename, "r");
    $this->buffer = fread($fp, filesize($filename));
    fclose($fp);
    $i=0;
    do {
    $result = ereg("<\[foreach\]>(.+)<\[\/foreach\]>",$this->buffer,$token);
    if ($result) {
    $this->foreach[] = $token[1];
    $this->buffer = ereg_replace("<\[foreach\]>.+<\[\/foreach\]>","<[foreach$i]>",$this->buffer);
    }
    } while ($result);
    }

    function setContent($name, $value) {

    if ($value == "") {

    if (gettype($name) == "array") {
    foreach($name as $k => $v) {
    $this->content[$k][] = $v;
    }
    }
    else {
    $this->content[$name][] = $value;
    }


    }//end_if


    else {$this->content[$name][] = $value;}
    }

    /*function setContent($name, $value = "") {

    if (gettype($name) == "array") {
    foreach($name as $k => $v) {
    $this->content[$k][] = $v;
    }
    } else {
    $this->content[$name][] = $value;
    }
    }*/

    function pre($var) {
    if ($this->debug == "DEBUG") {
    return "<!- begin:$var -->";
    }
    }

    function post($var) {
    if ($this->debug == "DEBUG") {
    return "<!- end:$var -->";
    }
    }

    function parse() {

    if ($this->debug == "DEBUG") {
    $pre = "<!- \$token[1] -->";
    $post = "<!- \$token[1] -->";
    }

    for($i=0;$i<count($this->foreach);$i++) {

    $result = ereg("<\[([[:alnum:]]+)\]>",$this->foreach[$i],$token);
    if ($result) {
    $iterations = count($this->content[$token[1]]);
    }
    for ($j=0;$j<$iterations;$j++) {
    $buffer = $this->foreach[$i];
    do {
    $result = ereg("<\[([[:alnum:]]+)\]>",$buffer,$token);
    if ($result) {
    $buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][$j].$this->post($token[1]),$buffer);
    }
    } while ($result);
    $this->content["foreach$i"][0] .= $buffer;
    }
    }

    do {
    $result = ereg("<\[([[:alnum:]]+)\]>",$this->buffer,$token);
    if ($result) {
    $this->buffer = ereg_replace("<\[$token[1]\]>",$this->pre($token[1]).$this->content[$token[1]][0].$this->post($token[1]),$this->buffer);
    }
    } while ($result);
    }

    function close() {
    echo $this->buffer;
    }

    function get() {
    return $this->buffer;
    }

    }

    ?>




    Sinceramente non ho capito a cosa serve. Potete aiutarmi. Grazie

  2. #2
    beh dovrebbe essere il codice relativo alla gestione del template dinamico


    http://forum.html.it/forum/showthrea...postid=4069797

  3. #3
    Grazie, vado subito a studiare!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.