PHP gute Anleitung Allgemeine Navigationsstrukturen Beispiel
Transcription
PHP gute Anleitung Allgemeine Navigationsstrukturen Beispiel
EWA SS 07 PHP gute Anleitung EWA SS 07 1 2 • http://www.professionelle-softwareentwicklung-mitphp5.de/erste_auflage/index.html EWA Navigation allgemein und mit PHP - Minitest Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp EWA SS 07 Dr. Ute Blechschmidt-Trapp Allgemeine Navigationsstrukturen 3 Beispiel Monohierarchie EWA SS 07 4 Nachrichten Inland Ausland Panorama Wirtschaft Aktien Chart Analysen Auflistu ng: Hotliste Linkliste Index Kurse Monohierarchie: Sitemap, Hypernet Sequenz: Wizard, Bestelldialog Polyhierarchie: Hypernet (häufig) Neuemissionen Gerichteter Graph: Hypernet (selten) Fonds Rating Dr. Ute Blechschmidt-Trapp Ratgeber Dr. Ute Blechschmidt-Trapp EWA SS 07 Navigationsentwurf Einfache Zustandsdiagramme 5 EWA SS 07 Zustandsdiagramm UWE 6 Zustandsdiagramm - endlicher Automat - Ereignisse ⇒ Zustandsänderungen eines Objekts Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp Navigationsentwurf EWA SS 07 EWA SS 07 (Kreling) 7 Navigationsentwurf 2 (Kreling) Zustände 8 generierte HTML-Seiten Login Passwort ändern Zustandsübergänge Persönliche Daten Lehrveranstaltungen belegen Semester auswählen Lehrveranstaltungen belegen Lehrveranstaltung(en) auswählen Logout Dr. Ute Blechschmidt-Trapp URL-Aufruf / Formular senden ! PHPProgramm ausführen Belegungen kontrollieren Dr. Ute Blechschmidt-Trapp EWA SS 07 9 Dynamische Seiten • HTML/PHP getrennt: <?php function HtmlHeader() { ?> <!DOCTYPE ... </head> <?php } ?> • oder echo "<!DOCTYPE ..." • Parameterüberprüfung: if (isset($_GET["page"]) && is_numeric($_GET["page"])) { include_once $_GET["page"]; EWA SS 07 10 Navigation, Herangehensweise • Was passiert beim Aufruf von index.php? • Was passiert beim Klicken eines Links im Menü? • Gegeben sei eine Liste mit DVDs, der Klick auf einen Eintrag soll die ausführliche Beschreibung des gewählten Videos inklusive Reservierungsmöglichkeit anzeigen. • Was passiert bei einer Suchanfrage? Dr. Ute Blechschmidt-Trapp EWA SS 07 11 Dr. Ute Blechschmidt-Trapp Navigationsstruktur • Dateisystem entspricht Navigationsstruktur – Dateisystem durchsuchen, darstellen • Navigationsstruktur ausgelagert in – Array – XML – Datenbank Dr. Ute Blechschmidt-Trapp EWA SS 07 12 Beispiel: Navigationsstruktur in Dateisystem • index.php – content • start.inc • WertpapiereUndPreise.inc – Geldanlage.inc – Aktien.inc – Investmentfonds.inc – GeschlosseneFonds.inc • KurseUndAnalysen.inc – Analysetools.inc – RealtimeKurse.inc • KontoUndDepot.inc – ... • ... Caption, externe Links??? Dr. Ute Blechschmidt-Trapp EWA SS 07 13 Beispiel: Navigationsstruktur in Array $menu = array( 0 => array( "url" => "/", "title" => "Home" ), 1 => array( "url" => "about/", "title" => "About PEAR" ), 2 => array( "url" => "download/", "title" => "Download", "sub" => array( 21 => array( "url" => "inside/cvs/", "title" => "CVS" ),... EWA SS 07 EWA SS 07 Beispiel: Navigationsstruktur in XML 14 <siteMap> <siteMapNode title="Home" caption="Home" url="default.php"> <siteMapNode title="Products" caption="Our products" url="Products.php"> <siteMapNode title="Hardware" caption="Hardware choices" url="Hardware.php"/ <siteMapNode title="Software" caption="Software choices" url="Software.php"/> </siteMapNode> <siteMapNode title="Services" caption="Services we offer" url="Services.php"> <siteMapNode title="Training" caption="Training classes" url="Training.php"/> <siteMapNode title="Consulting" caption="Consulting services" url="Consulting.php"/> </siteMapNode> </siteMapNode> </siteMap> ... Geschützer Bereich? oder <siteMapNode id="3" title="Services" caption="Services we offer" page="/Services.php" url="index.php?node=3" restrictedTo="customer"> Dr. Ute Blechschmidt-Trapp Dr. Ute Blechschmidt-Trapp Beispiel: Navigationsstruktur in Datenbank (klassisch) 15 EWA SS 07 16 Dr. Ute Blechschmidt-Trapp Beispiel: Navigationsstruktur in Datenbank (Nested Tree) Caption Id ParentId Left Right Level General Resources Code Paste Documentation Books & Publications Sql HTML HTML 4 XHTML 1 Links Databases Generators 1 2 3 4 5 6 7 8 9 10 11 1 1 1 2 22 3 1 2 Vervollständigen Sie die Tabelle. Dr. Ute Blechschmidt-Trapp Vorteile von Nested Trees EWA SS 07 18 • • EWA SS 07 (Abfragen für Menu) Beispiel für Books & Publications (Sitemap) – Vorarbeit: select * from Menu where id = 4 – (Alle) Unterpunkte von Books (Id = 4): • select * from Menu where Left >= $left and Right <= $right order by Left – Nur direkte Kinder: • select * from Menu where Left > $left and Right < $right and Level = $level + 1; Beispiel Breadcrumb für HTML 4 (id = 7) – Vorarbeit: select * from Menu where id = 7 – select * from Menu where Left <= $left and Right >= $right order by Level; 19 Nachteile von Nested Trees • Einfügen/Löschen/Verschieben von Knoten General Resources, Books & Publications, HTML, HTML4 Code: http://www.phpriot.com/d/articles/php/application-design/nested-trees-2/index.html Dr. Ute Blechschmidt-Trapp EWA SS 07 20 Dr. Ute Blechschmidt-Trapp Minitest EWA SS 07 • Bitte füllen Sie den Minitest über die bisherigen Inhalte anonym aus (20 min). Dr. Ute Blechschmidt-Trapp 21 • • • • Links <a href="../../../index.htm" rel="contents">Inhalt</a> <link rel="Index" href="../index.html" /> <link rel="Next" href="Chapter3.html" /> <link rel="Prev" href="Chapter1.html" /> Dr. Ute Blechschmidt-Trapp EWA SS 07 22 Apache mod_rewrite header • header("Location: http://www.example.com/"); EWA SS 07 /* redirect */ • header('content-type: text/html; charset=utf-8'); /* mime-type und charset */ • Insbesondere für Austausch mit anderen Applikationen: – header("Content-type: application/xhtml+xml"); – Problem IE (startet Download) <?php if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) { header("Content-type: application/xhtml+xml"); } else { header("Content-type: text/html"); } ?> Dr. Ute Blechschmidt-Trapp EWA SS 07 24 Zusammenfassung und Ausblick • Navigation – Zustandsdiagramme – möglichst dynamisch erzeugen, Strukturen veränderbar ablegen • nächste Woche: Datenbankzugriff, Cookies, Sessions Dr. Ute Blechschmidt-Trapp 23 Suchmaschinenfreundliche URLs • RewriteEngine on • RewriteRule ^/news/([0-9]+)\.html /news.php?news_id=$1 • Weitere Infos unter – http://www.phpriot.com/d/articles/php/applicationdesign/search-engine-urls/page2.html – http://httpd.apache.org/docs/1.3/mod/mod_rewrite. html – http://www.modrewrite.de/ Dr. Ute Blechschmidt-Trapp