Ankündigung

Einklappen
Keine Ankündigung bisher.

Erste Schritte mit Templates, bräuchte mal Hilfe ;)

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Erste Schritte mit Templates, bräuchte mal Hilfe ;)

    Kann mir jemand sagen warum des hier falsch ist?


    PHP-Code:
    <?php
    error_reporting
    (E_ALL);
    session_start();
    #Hier die Includes
    #require('class/dir.class.php');
    require('class/login.class.php');
    require(
    'class/link.class.php');
    require(
    'class/content.class.php');
    require(
    'class/sql.class.php');
    require(
    'class/news.class.php');
    require(
    'class/lil.class.php');
    require(
    'class/db_connect.php');
    require(
    "class/stats.class.php");
    require(
    "class/template.class.php");

    #Check ob login true
    if(isset($_POST['login_submit']) && $_POST['login_submit']=="Login"){
        
    $newLogin = new Login($_POST);
        
    $dsatz $newLogin->userlogin();
        
    $_SESSION['user_active'] = $dsatz["user_active"];
        
    $_SESSION['username'] = $dsatz["username"];
        
    $_SESSION['user_password'] = $dsatz["user_password"];
        
    $_SESSION['user_level'] = $dsatz["user_level"];
        
    $_SESSION['user_new_privmsg'] = $dsatz["user_new_privmsg"];
        
    $_SESSION['user_rank'] = $dsatz["user_rank"];
        
    $_SESSION['user_email'] = $dsatz["user_email"];
        
    $_SESSION['user_website'] = $dsatz["user_website"];
        
    $_SESSION['user_sig'] = $dsatz["user_sig"];
        
    $_SESSION['user_from'] = $dsatz["user_from"];
    }
    #Check ob Site neu aufgemacht
    if(!isset($_GET['cid'])){
        
    $_GET['cid'] = 1;
    }
    if(!isset(
    $_GET['kat_id'])){
        
    $_GET['kat_id']=1;
    }

    #neue Klassen erstellen

    #########Hier die Links
    $newLink = new Link();
    $newLink->selectLinks($_GET['kat_id']);
    #########Content-Klasse
    $newContent = new Content();
    $newContent->selectContent($_GET['cid']);
    ##Die kleine Klasse
    $lil = new Lil();

    ##Templates laden
    $tpl_content = new Template("content.html");
    $tpl_footer = new Template("footer.html");
    $tpl_head = new Template("head.html");
    $tpl_nav = new Template("nav.html");


    $tpl_head->assign('TITLE'"EGC-Online       ".(!empty($_SESSION['username']) ? "Wer ist der geilste User? Antwort:".$_SESSION['username'] : ''));
    $tpl_head->assign('PAGETITEL'"EGC-Online");
    $tpl_nav->assign('HAUPTLINKS'$newLink->flushLink());
    $tpl_nav->assign('LEFTMENU'$lil->getUser());
    $tpl_nav->assign('LOGGEDAS', (!empty($_SESSION['username']) ? "Logged as:" ''));
    $tpl_nav->assign('USERNAME', (!empty($_SESSION['username']) ? $_SESSION['username'] : ''));
    $tpl_nav->assign('DATE'date("d.m.Y"));
    $tpl_nav->assign('TIMENOW'date("H:i"));
    $tpl_content->assign('CONTENT'$newContent->flushContent());
    $tpl_footer->assign('USERNAME', (!empty($_SESSION['username']) ? $_SESSION['username'] : ''));

    $tpl_head->out();
    $tpl_nav->out();
    $tpl_content->out();
    $tpl_footer->out();
    ?>


    bei mir kommt nämlich erst das nav raus, dann der Content, dann der head, und dann der footer......komisch wa?

    Is nu mein erster Versuch mit Templates..
    hab ich evtl. was übersehn? *grübel*

  • #2
    Welche Template Engine ? Smarty?

    Edit:
    ok, eher nicht.
    Diese Erweiterung ist EXPERIMENTELL.
    [...]
    Seien Sie gewarnt und verwenden Sie diese Erweiterung auf eigenes Risiko..

    Kommentar


    • #3
      PHP-Code:
      <?php

      define
      ("TEMPLATE_ERR_FILE","Could not load template file.");

      /**
       * Apolda Simple Template class. 
       * This file is part of Apolda Web Tool Suite.
       *
       * The complete apolda classes are distributed under the 
       * GNU Lesser General Public License.
       * See the lesser.txt file for details.
       * 
       * @author    Ralf Geschke <ralf@kuerbis.org>
       * @copyright 2002 by Ralf Geschke
       * @version   $Id: class_template.inc.php,v 1.6 2002/07/16 09:05:07 geschke Exp $
       * @access    public
       */
      class Template
      {

          var 
      $delimiterStart "{";
          var 
      $delimiterEnd "}";

          var 
      $t;
          var 
      $pl;
         
          var 
      $templatefile;
          
          
      /**
           * Constructor function. 
           * If a template filename is submitted, this function will
           * initialize the template object tree.
           *
           * @param    string $filename  Name of template file.
           * @access   public
           * @return   void
           */
          
      function Template($filename "")
          {
              
      /* todo: 
                 - remove setting error messages from constructor 
                 ( to a base class ? )
               */
              
      $this->loadTemplateFile($filename);
          }

          
      /**
           * Set start delimiter
           * Call this function if you wish to change the default start
           * delimiter '{' to another character.
           * 
           * @param    string $delim
           * @return   void
           */
          
      function setStartDelim($delim="{"
          {
              
      $this->delimiterStart $delim;
              }

          
      /**
           * Set end delimiter
           * Call this function if you wish to change the default end
           * delimiter '}' to another character.
           *
           * @param    string $delim
           * @return   void
           */
          
      function setEndDelim($delim="}"
          {
              
      $this->delimiterEnd $delim;
              }
          

          
      /**
           * Load and initialize template file.
           * This is only useful if it is not possible to 
           * set a template filename by creating an instance of
           * the template class.
           * 
           * @param    string $filename  Name of template file.
           * @access   public
           * @return   void
           */
          
      function loadTemplateFile($filename "")
          {
              global 
      $config;

              if (!
      $filename)
              return 
      false;
              if (
      $filename)
              
      $this->templatefile "./templates/".$filename;
              if (!
      $fp = @fopen($this->templatefile,'r'))
              {
              die(
      TEMPLATE_ERR_FILE);
              }
              
      $this->fread($fp,filesize($this->templatefile));
              
      fclose($fp);
              
      $this->_initTemplate();
          }

          
      /**
           * Submit a string variable as template content.
           * This is useful if your template doesn't exist as file,
           * e.g. if it is saved in a database.
           * 
           * @param    string $templatestring
           * @access   public
           * @return   void
           */
          
      function loadTemplateContent($templatestring="")
          {
              
      $this->$templatestring;
              
      $this->_initTemplate();
          }

          
      /**
           * Parse the template.
           * This function creates the template object tree and replaces contents
           * of blocks with simple placeholders. 
           * 
           * @access   private
           * @return   void
           */
          
      function _initTemplate()
          {
              
      preg_match_all("/\s*\n*\s*(.*)\s*\n*\s*/ms",$this->t,$ma);
              for (
      $i 0$i count($ma[0]); $i++)
              {
              
      $search "/\s*\n*(.*)\s*\n*/ms";
              
      $replace $this->delimiterStart $ma[1][$i] . $this->delimiterEnd;
              
      $this->bl[$ma[1][$i]] =& new Template();
              
      $this->bl[$ma[1][$i]]->loadTemplateContent($ma[2][$i]);
              
      $this->preg_replace($search,$replace,$this->t);
              }
          }

          
      /**
           * Fetch a block out of the template. 
           * If the block exists, this function returns a Template object,
           * otherwise nothing (false).
           * When parsing the template, the blocks will removed
           * into Template objects and replaced with placeholders. 
           * The name of the placeholder is identical to the name 
           * of the removed block.
           * 
           * @param    string $blockName
           * @access   public
           * @return   object Template or boolean false
           */
          
      function fetchBlock($blockName)
          {
              if (isset(
      $this->bl[$blockName]))
              return 
      $this->bl[$blockName];
              else
              return 
      false;
          }

          
      /**
           * Assign value to an existing placeholder. 
           * If this function is called multiple, the contents
           * will be added. 
           * 
           * The parameter $varName can be a string, an associative 
           * array or a Template object. 
           * 
           * @param    mixed $varName
           *           Allowed types:    Requirements:
           *           string            $varValue            
           *           array             Array format: 
           *                             array ("name_of_placeholder" => Value,
           *                                    ... )
           *           object            Template object or any object which
           *                             returns HTML code via get() method.
           *
           * @param    string $varValue (optional)
           * @access   public
           */
          
      function assign($varName,$varValue=false)
          {
              if (
      is_array($varName))
              {
              foreach (
      $varName as $key => $value)
                  {
                  
      $this->pl[$key][] = $value;
                  }
              }
              else
              {
              
      $this->pl[$varName][] = $varValue;
              }
          }

          
      /**
           * Delete the contents of submitted variables.
           * 
           * @param    none
           * @access   public
           */
          
      function reset()
          {
              unset(
      $this->pl);
          }

          
      /**
           * Print a template with all replacements done.
           * 
           * @param    none
           * @access   public
           */
          
      function out()
          {
              print 
      $this->get();
          }

          
      /**
           * Returns a template with all replacements done. 
           * 
           * @param    none
           * @access   public
           * @return   string parsed template content
           */
          
      function get()
          {
              if (
      is_array($this->pl))
              {
              foreach (
      $this->pl as $key => $value)
                  {
                  
      $search $this->delimiterStart $key $this->delimiterEnd;
                  
      $replaceText "";
                  for (
      $i 0$i count($this->pl[$key]); $i++)
                  {
                      if (
      is_object($this->pl[$key][$i]))
                      
      $replaceText .= $this->pl[$key][$i]->get();
                      else
                      
      $replaceText .= $this->pl[$key][$i];
                  }
                  
      $this->str_replace($search,$replaceText,$this->t);
                  }
              }
              return 
      $this->t;
          }

      }
      ?>

      Kommentar


      • #4
        Ähm, soll ichs lieber ins Fortgeschrittenen Forum posten?

        Kommentar


        • #5
          info@Julied64:

          Mein Browser mag deine Seite ---> www.park-to-fly.de <--- nicht!

          Ist das von dir so gewollt,
          daß nicht jeder mit jedem beliebigen Browser die Seite besuchen kann?
          Oder gibts dort noch nichts zu sehen?

          ~dilemma~

          Kommentar

          Lädt...
          X