Php Template Class I Started - and a good way to see how to fail template class

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Php Template Class I Started - and a good way to see how to fail template class

matak
Althought it works, and maybe some users can even use this class for some simpler websites, this is not a good way to create class. I cant really explain why, and i'm publishing it so maybe people with more experience in template design can help me figure out how to create PHP templates. Looking forward for your answers.

some of the variables and directories are in croatian, but i don't think that matters when you look at with programmers eyes.

First my index.php file looks like this...

CODE
<?php     include ("includes/showSiteClass.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>jednostavno.com - Jednostavno o Web dizajnu i programiranju - <?php $ypSiteModules->showTitle(); ?></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="css.css">
<style type="text/css">

</style>
</head>
<body>
<div id="gore"><?php $ypSiteModules->showMainLinks($_GET); ?></div>

<div id="lijevo"><?php $ypSiteModules->showSubLinks($_GET); ?>

<div id="desno"><?php $ypSiteModules->showContent(); ?></div>

</body>
</html>


showSiteClass.php is this

CODE
<?php error_reporting(E_ALL); ?>
<?php

    class c1ShowContent {
        
        private $variable = array (                 "index"    => array ("PHP Open source sustav" => "opensource"),
                                    "HTML" => array ("Pisanje HTML koda [HTML 0001]" => "pisanjehtmla"),
                                    "PHP"    => array ("Instalacija Xampp [PHP 0001]" => "instalacijaxampp"    )
                                    );
    
        public function showMainLinks($fun) {
            echo "<div class=\"mainLinkovi\"><ul>";
            foreach ($this->variable as $key => $val) {
                echo "<li><a href=\"?main=".$key."\">$key</a></li>";
            }
            echo "</ul></div>";
            $mainKeys = array_keys ($this->variable);
            
        
            if (empty($_GET['main'])) {
                $this->link = $this->variable["index"];
                $this->main = $this->variable = "index";
            }
            elseif (in_array($_GET['main'], $mainKeys)) {
                $this->link = $this->variable[$_GET['main']];
                $this->main = $_GET['main'];
            }
            else {
                $this->link = $this->variable["index"];
                $this->main = $this->variable = "index";
            }
        
        }
        
        public function showSubLinks($fun){
            echo "<div class=\"subLinkovi\"><p>Sadržaj - $this->main</p>";
            echo "<ul>";
            foreach ($this->link as $key => $val) {
                echo "<li><a href=\"?main={$this->main}&amp;sub=".$key."\">$key</a></li>";
            }
            echo "</ul></div>";
            $subKeys = array_keys ($this->link);
            $this->subKeys  =$subKeys;
            
            if (empty($_GET['sub'])){
            $this->content = $this->main;
            }
            elseif (in_array($_GET['sub'], $subKeys)) {
            $this->content = $this->link[$_GET['sub']];
            }
            else {
            $this->content = $this->main;
            }
        }
            
        public function showContent(){
            include "stranice/$this->main/$this->content.html";
            
            $filename = "stranice/$this->main/$this->content.html";
                if (file_exists($filename)) {
                    echo "<p class=\"ftime\">Dodano: " . date ("d F Y H:i:s.", filemtime($filename))."</p>";
                    }
        }
        
        public function showTitle() {
        
            $mainKeys = array_keys ($this->variable);
                                    
            if (empty($_GET['main'])) {
            $this->title = "index";
            }
            elseif (!empty($_GET['main']) && empty($_GET['sub'])) {
            if (in_array($_GET['main'], $mainKeys)){
            $this->title = $_GET['main'];
            }
            else {
            $this->title = "index";
            }
            }
            elseif (!empty($_GET['sub'])) {
            $this->link = $this->variable[$_GET['main']];
            $subKeys = array_keys($this->link);
            if (in_array($_GET['sub'], $subKeys)){
            $this->title = $_GET['sub'];
            }
            else {
            $this->title = "index";
            }
            }
        
        echo $this->title;
        }
        
    }

$ypSiteModules = new c1ShowContent;
?>


directory sturcture on root is

-includes
--showSiteClass.php

-stranice
--index
---index.html
---opensource.html

--HTML
---HTML.html
---pisanjehtmla.html

--PHP
---PHP.html
---instalacijaxampp.html

index.php

Problem i found on this class, that it's not dynamic enough. It's fast, and i think it's secure enough, but i got some problems when i wanted to include some pages EG. contact.php, that need another included file eg mailto.php, and can't figure out a way to solve that problem, except by including it in index.php file at start, but than it would be availiable to any file i have, and that's not an option.

I tried to find many good tutorials on writing PHP template system, and am trying to avoid smarty, beacouse i preffer to use my own templating system until i become more familliar with the way it works.

If you had experience in building such a system, please help.

Main problem i think is, array that sets pages, beacouse it's really crude for now, and i need to make it more justifiable (dunno the proper word).

Thanks for any help.

 

 

 


Reply

reconraiders
That's usually the way most progs do it. You can make a file called functions.php or something and include that mail function as well as many other functions. Then whenever you need to use it just call the function.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php template started fail template

  1. Template Chooser? - (10)
  2. [php]diffrent Type Of Template [id] With Includes ;) - (13)
    ?> Example <!-- A { color: #003366;
    text-decoration: none; } A:link { color: #003366; text-decoration: none; }
    A:visited { color: #003366; text-decoration: none; } A:active { color:
    #54622D; } A:hover { color: #54622D; } BODY,TD,TR{ font-family:
    verdana, arial, sans-serif; color:#000; font-size:11;
    font-weight:normal; } .banner { font-family: georgia, verdana, arial, sans-serif; ...
  3. Error With Joomla Template - cant find function (1)
    Hello! I am working on my template in Dreamweaver and i am using joomla extensions for
    dreamweaver! When i start my page with joomla stand alone server(jsas) i get this errors on the
    bottom of the page! QUOTE Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla\includes\frontend.php on line 66 Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla�...
  4. Tpl (template System) And Php - Question (2)
    Hi all i search about tpl and php i want make and learn how can use tpl (template system ) in php do
    you link or tutorial ? plz post here or if you know plz paster here simple sample about php and tpl
    thanks more Proper spelling is required as a Trap17 member. Refrain from using slang spelling. ...
  5. What's The Best Place To Learn Php? - help a newb get started (11)
    I've never touched PHP or MySQL before /unsure.gif' border='0' style='vertical-align:middle'
    alt='unsure.gif' /> . My experience is regular HTML and CSS. Could someone please link me to a
    site with a good, easy, free online tutorial for a newb like me? Thanx much in advance!
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> ...
  6. Name The Customized Template - for my look and feel (12)
    i have a easy to use and easy to expand php look and feel but dont know what to name it. It allready
    has a great folder structure and some ok tools. Also you can make your own extensions and change
    allmost EVERYTHING. I have bg images, bg colors, nice look but it uses tables. i have it currently
    working in firefox and IE, the only good ad free browsers. Original title "I Need A Name." What
    you need is better topic title. This is the only caution note. ...
  7. Extra Page With Same Template - (0)
    I've installed Coppermine (online photoalbum manager) on My Webpage but i would like to add an
    extra(s) page with other content. I mean, building an extra page with the same template/theme in in
    the site. I guess some scripts have to be copied into a new page, but i don't know which ones...
    I'm not familiar (enough) with coding.. The menu,backgroundcolor, css and footer should be the
    same.... I hope someone can help me with this, thanks in advance! /cool.gif' border='0'
    style='vertical-align:middle' alt='cool.gif' /> (spread the knowledge /wink.gi...



Looking for php, template, class, started, fail, template, class

Searching Video's for php, template, class, started, fail, template, class
advertisement



Php Template Class I Started - and a good way to see how to fail template class



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE