commit
328b036d65
@ -0,0 +1,79 @@
|
||||
\documentclass[6pt,headings=small]{scrartcl}
|
||||
\usepackage[utf8x]{inputenc}
|
||||
\usepackage[paper=a4paper,left=10mm,right=10mm,top=10mm,bottom=10mm,landscape]{geometry}
|
||||
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
|
||||
|
||||
\RedeclareSectionCommand[
|
||||
beforeskip=-.75\baselineskip,
|
||||
afterskip=.25\baselineskip]{section}
|
||||
\RedeclareSectionCommand[
|
||||
beforeskip=-.5\baselineskip,
|
||||
afterskip=.25\baselineskip]{subsection}
|
||||
\RedeclareSectionCommand[
|
||||
beforeskip=-.25\baselineskip,
|
||||
afterskip=.25\baselineskip]{subsubsection}
|
||||
|
||||
\usepackage{multicol}
|
||||
\setlength{\columnsep}{0.2cm}
|
||||
|
||||
% fancy code highlighting :D
|
||||
\usepackage{minted}
|
||||
|
||||
\definecolor{darkgreen}{rgb}{0.0,0.4,0.0}
|
||||
\usepackage{enumitem}
|
||||
\usepackage[Q=yes]{examplep}
|
||||
|
||||
\setlength{\parskip}{0.7ex plus 0.5ex minus 0.2ex}
|
||||
\setlength{\parindent}{0ex}
|
||||
|
||||
\usepackage[
|
||||
pdftitle={Cheatsheet Web-Engineering},
|
||||
pdfsubject={HTML, PHP \& JSF},
|
||||
pdfauthor={Thomas Battermann},
|
||||
pdfkeywords={PHP, HTML, JSF, Cheatsheet, Web-Engineering, DHBW},
|
||||
pdfborder={0 0 0}
|
||||
]{hyperref}
|
||||
|
||||
\pagenumbering{gobble}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\begin{multicols}{4}
|
||||
|
||||
\section{HTML}
|
||||
\inputminted[tabsize=3,showtabs=false,breaklines=true]{html}{src/html.html}
|
||||
|
||||
\section{PHP}
|
||||
|
||||
\subsection{Funktionsreferenz}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/befehle.php}
|
||||
|
||||
\subsection{CSV}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/csv.php}
|
||||
|
||||
\subsection{MySQLi}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/mysqli.php}
|
||||
|
||||
\subsection{Sessions}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/sessions.php}
|
||||
|
||||
\subsection{OOP}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/oop.php}
|
||||
|
||||
\subsection{Kontrollstrukturen}
|
||||
\inputminted[tabsize=4,showtabs=false,breaklines=true]{php}{src/kontrollstrukturen.php}
|
||||
|
||||
\section{JSF}
|
||||
|
||||
\subsection{Template}
|
||||
\inputminted[tabsize=2,showtabs=false,breaklines=true]{html}{src/template.xhtml}
|
||||
|
||||
\subsection{registerCustomer}
|
||||
\inputminted[tabsize=2,showtabs=false,breaklines=true]{html}{src/reg.xhtml}
|
||||
|
||||
\subsection{ManagedBean Customer.java}
|
||||
\inputminted[tabsize=2,showtabs=false,breaklines=true]{java}{src/customer.java}
|
||||
|
||||
\end{multicols}
|
||||
|
||||
\end{document}
|
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// Optionale Parameter sind als Kommentar angegeben!
|
||||
// Ausgeben eines Strings:
|
||||
echo( $string ); // alternativ:
|
||||
print( $string );
|
||||
// Formatiertes ausgeben eines String:
|
||||
// Wie C-Funktion:
|
||||
// - %d → Ganzzahl
|
||||
// - %f → Float
|
||||
// - %.2f → Float (2 Nachkommastellen)
|
||||
// - %s → String
|
||||
printf( $string, $var /* [, $...] */ );
|
||||
// Formatiertes Datum Ausgeben:
|
||||
// d: Tag des Monats (führende 0) h: Stunde (1-12)
|
||||
// D: Tag der Woche (Sun-Sat) H: Stunde (0-23)
|
||||
// m: Monat (führende Null) Y: Jahr (4stellig)
|
||||
// y: Jahr (zweistellig) a/A: am/pm / AM/PM
|
||||
// j: Tag des Monats (1-31) H: Stunde (0-23)
|
||||
// w: Wochentag (0=So-6=Sa) i: Minute (00-59)
|
||||
// c: 2004-02-12T15:19:21+00:00 O: Zeitzone (+0200)
|
||||
// r: Thu, 21 Dec 2000 16:01:07 +0200 s: Sekunde (00-59)
|
||||
date( $format /*, $timestamp */ );
|
||||
date( "Y-m-d" ); // 2015-11-24
|
||||
// Gibt die Länge des String zurück
|
||||
$length = strlen( $string );
|
||||
// Gibt Teilstring ab start zurück; Länge=$length oder bis Ende
|
||||
substr( $string, $start /*, $length */ );
|
||||
substr( "abcd", 2, 1 ); // "c"; Ohne 3. Parameter: "cd"
|
||||
// Ersetzt search durch replace im String subject und gibt diesen String zurück
|
||||
str_replace( $search, $replace, $subject );
|
||||
str_replace("bc","1","abcd"); // → "a1d"
|
||||
// Konvertiert folgende Zeichen in HTML-Entitäten:
|
||||
// & " ' < > zu & " ' < >
|
||||
htmlspecialchars( $string );
|
||||
// Gibt nächste kleinere Integer zurück
|
||||
floor( $float );
|
||||
// Äquivalent zu htmlspecialchars, es werden allerdings alle Zeichen ersetzt, für die es entsprechende HTML-Entitäten gibt
|
||||
htmlentities( $string );
|
||||
// Prüft ob Variable(n) exisiteren und nicht NULL sind
|
||||
isset( $var /* , $... */ );
|
||||
// Prüft ob Variable ein String ist.
|
||||
is_string( $var );
|
||||
// Prüft ob Variable eine Ganzzahl ist.
|
||||
is_int( $var );
|
||||
// Prüft ob eine Variable/ein String eine Zahl darstellt.
|
||||
is_numeric( $var );
|
||||
// Öffnet eine Datei mit einem der Modi:
|
||||
// "r": Lesen; Zeiger am Anfang der Datei
|
||||
// "w": Schreiben; Zeiger am Anfang der Datei, Datei wird auf Länge 0 gekürtzt
|
||||
// "a": Schreiben; Zeiger am Ende der Datei → Inhalte anhängen
|
||||
// Sowie "r+", "w+" und "a+": Jeweils lesen und schreiben
|
||||
fopen( $filename, $mode );
|
||||
// Schreibt string in Datei (handle)
|
||||
fputs( $handle, $string );
|
||||
// Liest eine Zeile aus handle
|
||||
fgets( $handle /*, $length */ );
|
||||
// Testet auf End-of-File auf einem handle.
|
||||
feof( $handle );
|
||||
// Schließt die Datei
|
||||
fclose( $handle );
|
||||
// Liest die Datei und gibt sie aus
|
||||
readfile( $filename );
|
||||
// Liest die Datei und gibt sie als String zurück
|
||||
file_get_contents( $filename );
|
||||
// Gibt ein Array mit den Zeilen der Datei zurück
|
||||
file( $file );
|
||||
// Liest einen CSV-Eintrag
|
||||
fgetcsv( $handle /* , $length=0, $delimiter=",", $enclosure='"', $escape="\" */ );
|
||||
// Schreibt einen CSV-Eintrag
|
||||
fputcsv( $handle, $fields /*, $delimiter=",", $enclosure='"', $escape_char="\" */ );
|
||||
// Formatiert eine Zahl (Englisches Format!)
|
||||
number_format( $number /*, $decimals = 0*/ );
|
||||
// Formatiert eine Zahl mit gegebenen Zeichen
|
||||
number_format( $number, $decimals = 0, $dec_point = ".", $thousands_sep = "," );
|
||||
// Definiert eine Konstante zur Laufzeit
|
||||
define( $name, $value );
|
||||
// Setzte ein Locale (z.B.: LC\_ALL, de\_DE)
|
||||
setlocale( $category, $locale );
|
||||
// aus Vorlesung:
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
|
||||
// Bindet eine Datei ein, gibt Warnung aus, wenn diese nicht existiert
|
||||
include( $file );
|
||||
// Wie include, gibt aber einen Fehler zurück, wenn Datei nicht existiert
|
||||
require( $file );
|
||||
// Versucht einen String in einen Timestamp umzuwandeln
|
||||
strtotime( $string );
|
||||
// Heredoc
|
||||
$s = <<<Inhalt
|
||||
Hier können mehrere Zeilen Text stehen
|
||||
Inhalt kann bel. Wort als Trenner sein.
|
||||
Inhalt;
|
||||
// Funktion mit optionalem Parametern:
|
||||
function foo($var1, $opt1="blah") { /* ... */ }
|
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// open file handle
|
||||
$fh = fopen("file.csv","a");
|
||||
// write new line
|
||||
fputcsv( $fh, array( date("Y-m-d"), $data ) );
|
@ -0,0 +1,21 @@
|
||||
@ManagedBean
|
||||
@SessionScoped
|
||||
public class Customer {
|
||||
private String name;
|
||||
@ManagedProperty(value="beispiel@example.com")
|
||||
private String mail;
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getMail() { return mail; }
|
||||
public void setMail(String mail) { this.mail = mail; }
|
||||
public String save() { /*TODO*/ return "next"; }
|
||||
public void mailAddressChanged(ValueChangeEvent e) {
|
||||
System.out.println("Old value: " + e.getOldValue());
|
||||
System.out.println("New Value: " + e.getNewValue()); }
|
||||
public void validateGender(FacesContext ctx, UIComponent com, Object value)
|
||||
throws ValidatorException {
|
||||
String sex = value.toString();
|
||||
if ( sex.compareTo("m") != 0 && sex.compareTo("w") != 0 && sex.compareTo("n") != 0) {
|
||||
FacesMessage msg=new FacesMessage(FacesMessage.SEVERITY_ERROR,"Fehler!",null);
|
||||
throw new ValidatorException(msg);
|
||||
} } }
|
@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html> <!-- \n --> <head>
|
||||
<title>Titel eines Dokuments</title>
|
||||
<!-- kommentar innerhalb HTML -->
|
||||
<style type="text/css">
|
||||
/* Kommentar innerhalb CSS */
|
||||
h1 { /* Selektor für ein HTML-Tag*/
|
||||
color:red; text-align:center; }
|
||||
#content { /* Selektor für ID */
|
||||
font-family:monospace; }
|
||||
.small { /* Selektor für Klassen*/
|
||||
font-size:8px; }
|
||||
@media(max-device-width: 480px) {
|
||||
/* für Geräte mit Breite < 480px */
|
||||
.small{font-size:12px} }
|
||||
</style>
|
||||
</head> <!-- \n --> <body>
|
||||
<h1>Titel</h1> <h2>Untertitel</h2>
|
||||
<div id="content"><!-- block element -->
|
||||
<p>Absatz<br/>mit Zeilenumbruch und
|
||||
<a href="ziel.html">Link</a></p>
|
||||
<p><span style="color:blue">blau</span></p>
|
||||
<hr/><!-- horizontale trennlinie -->
|
||||
<table border="1"><!-- begin tabelle -->
|
||||
<tr><!-- zeile -->
|
||||
<td>1. Zelle <strong>Fett</strong></td>
|
||||
<td>2. Zelle <em>kursiv</em></td>
|
||||
</tr><!-- ende zeile -->
|
||||
</table><!-- ende tabelle -->
|
||||
</div>
|
||||
<form method="post" action="ziel.php">
|
||||
<label for="id-name">Name:</label>
|
||||
<input type="text" name="name" id="id-name" />
|
||||
<!-- type: text/password/checkbox/radio/... -->
|
||||
<textarea name="text"></textarea>
|
||||
<select size="4" name="liste"><option>1</option>
|
||||
<option>...</option></select>
|
||||
<!-- ohne size="n" als DropDown -->
|
||||
<input type="submit" value="Absenden" />
|
||||
</form>
|
||||
</body> <!-- \n --> </html>
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
if ( $bool ) { /* ... */
|
||||
}elseif( !$bool ) { /* ... */
|
||||
}else{ /* ... */ }
|
||||
for($i=0; $i<10; $i++) {echo($i);}
|
||||
while(true) { /* do something */ }
|
||||
do{ /* do something*/ }while(true);
|
||||
foreach($array AS $key => $value) { /* ... */ }
|
||||
foreach($array AS $value) { /* ... */ }
|
@ -0,0 +1,10 @@
|
||||
<?php // Verbindung aufbauen, Parameter optional:
|
||||
$link = mysqli_connect( $host, $username, $passwd, $dbname, $port);
|
||||
$query = "SELECT id, text FROM table";
|
||||
$result = mysqli_query($link, $query); // SQL Ausführen
|
||||
while( $row = mysql_fetch_row( $result) ) // Ergebnisse abfragen
|
||||
echo("ID ".$row[0].": ".$row[1]."\n");
|
||||
while( $row = mysql_fetch_assoc( $result) ) // Alternative Methode: Spaltennamen als Indizes des Arrays
|
||||
echo("ID ".$row["id"].": ".$row["text"]."\n");
|
||||
mysqli_query($link, "INSERT INTO table (text) VALUES ('test')"); // Zeile einfügen
|
||||
$id = mysqli_last_insert_id( $link ); // ID des Eintrags auslesen (Autoincrement der Spalte id)
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class Fahrzeug {
|
||||
public $farbe;
|
||||
public function __construct($farbe) {
|
||||
$this->farbe = $farbe; }
|
||||
public function getFarbe() { return $farbe; }
|
||||
// Spezialfunktionen: __call, __get, __set
|
||||
}
|
||||
class Auto extends Fahrzeug { /* ... */ }
|
||||
$auto = new Auto("blau");
|
||||
$kopie = clone $auto;
|
@ -0,0 +1,26 @@
|
||||
<!-- headers... -->
|
||||
<f:view locale="#{customer.lang}">
|
||||
<ui:composition template="meinTemplate.xhtml">
|
||||
<ui:define name="header">#{msgs.title_register_customer}</ui:define>
|
||||
<ui:define name="content">
|
||||
<h:graphicImage library="images" name="logo.gif" />
|
||||
<h1><h:outputText value="#{msgs.title_main}"/></h1>
|
||||
<h2><h:outputText value="#{msgs.title_register_customer}" /></h2>
|
||||
<h:messages />
|
||||
<h:form id="regform">
|
||||
<h:panelGrid columns="2">
|
||||
<h:outputLabel for="VName" value="VName" />
|
||||
<h:inputText id="Vorname" value="#{customer.firstName}" validatorMessage="2 < VName < 30">
|
||||
<f:validateLength minimum="2" maximum="30" />
|
||||
</h:inputText>
|
||||
<h:outputLabel for="EMail" value="E-Mail" rendered="#{param.mail.compareTo('no') != 0}"/>
|
||||
<h:inputText id="EMail" value="#{customer.mailAddress}" rendered="#{param.mail.compareTo('no') != 0}" valueChangeListener="#{customer.mailAddressChanged}" validatorMessage="Provide valid mail!">
|
||||
<f:validateRegex pattern=".*@.*" />
|
||||
</h:inputText>
|
||||
</h:panelGrid>
|
||||
<h:commandButton value="Absenden" action="next" />
|
||||
<h:commandButton value="Registrierung abbrechen" immediate="true" action="cancel" />
|
||||
</h:form>
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
</f:view>
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// Session starten
|
||||
session_start();
|
||||
// Zugriff auf Session-Variable
|
||||
$_SESSION["index"] = "123";
|
||||
// Löscht alle in einer Session registrierten Daten
|
||||
session_destroy();
|
||||
// Liefert und/oder setzt die aktuelle Session-ID
|
||||
session_id( /* $string */ );
|
||||
// Überprüft, ob eine globale Variable in einer Session registriert ist
|
||||
session_is_registered(); // deprecated
|
||||
// Löscht alle Session-Variablen
|
||||
session_unset();
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
|
||||
xmlns:f="http://xmlns.jcp.org/jsf/core">
|
||||
<f:view>
|
||||
<body style="width:500px; margin:0.5em auto;">
|
||||
<div id="title">
|
||||
<h1><h:outputText value="#{msgs.title_main}"/></h1>
|
||||
<ui:insert name="header">Header-Text</ui:insert>
|
||||
</div> <div id="content">
|
||||
<ui:insert name="content">Seiteninhalt</ui:insert>
|
||||
</div> <div id="footer">Letzte aktualisierung:
|
||||
<ui:insert name="footer">11.11.2011</ui:insert>
|
||||
</div> </body>
|
||||
</f:view> </html>
|
Loading…
Reference in new issue