\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Sara (lasago)} \pdfinfo{ /Title (dwcs-objetos.pdf) /Creator (Cheatography) /Author (Sara (lasago)) /Subject (DWCS - Objetos Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{BD91FF} \definecolor{LightBackground}{HTML}{F6F1FF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{DWCS - Objetos Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Sara (lasago)} via \textcolor{DarkBackground}{\uline{cheatography.com/70899/cs/18804/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Sara (lasago) \\ \uline{cheatography.com/lasago} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 29th May, 2019.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{6.7353 cm} x{10.5347 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Conexión}} \tn % Row 0 \SetRowColor{LightBackground} nueva conexión & \$conn = new mysqli("localhost", "root", "", "tiendao"); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} mostrar error de conexión & \$conn-\textgreater{}connect\_error \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} matar conexión & die(); \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Consultas desde PHP a BD}} \tn % Row 0 \SetRowColor{LightBackground} crear consulta & \$query = \$conexion-\textgreater{}query(\$sql); \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} número de filas de la consulta & \$query-\textgreater{}num\_rows \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} mientras haya filas, guardar array & while( \$row = \$consulta-\textgreater{}fetch\_assoc() ) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} imprimir valor dentro de la clave codigo & echo \$row{[}'codigo'{]} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.1169 cm} x{9.1531 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Cookies y sesiones}} \tn % Row 0 \SetRowColor{LightBackground} crear cookie & //nombre, valor, expires, path, domain, secure, httponly setcookie('tema', \$tema, time() + (60 * 1)); \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} variable de cookie & \$\_COOKIE{[}'tema' \tn % Row Count 7 (+ 1) % Row 2 \SetRowColor{LightBackground} iniciar sesión & session\_start(); \tn % Row Count 8 (+ 1) % Row 3 \SetRowColor{white} valor de sesión & \$\_SESSION{[}'usuario'{]} = \$\_POST{[}'usuario'{]}; \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} regenerar id de sesión & \seqsplit{session\_regenerate\_id();} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} deshacer sesión, detsruír sesión & session\_unset(); session\_destroy(); \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} declarar tiempo de sesión & \$\_SESSION{[}"timeout"{]} = time(); \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} & \$sessionTTL = time() - \$\_SESSION{[}"timeout"{]}; \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} x{15.543 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Rutas}} \tn % Row 0 \SetRowColor{LightBackground} & \seqsplit{spl\_autoload\_register('mi\_autoloader');} include\_once \$NombreClase . '.php'; \$sara = new Persona() \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{Namespace} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{\_DIR\_} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{alias} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} & define("RUTA", \seqsplit{realpath(dirname(\_\_FILE\_\_))}.DS ); \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} & define("DS", DIRECTORY\_SEPARATOR); \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{transaction}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{a} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{p{1.727 cm} p{1.727 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{consultas}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{bloqueo query} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{transaction} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{bloqueo tabla} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.3175 cm} x{12.9525 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{ficheros}} \tn % Row 0 \SetRowColor{LightBackground} crear & \$f = fopen(\$obj-\textgreater{}ruta,'a+') \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} escribir & fwrite(\$f,serialize(\$o).PHP\_EOL); \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} leer & \$f = fopen(\$this-\textgreater{}ruta,'r'); \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} & while(!feof(\$f))\{ \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} & \$u = unserialize(fgets(\$f)); \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} & \$a{[}{]} = \$u; \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{-} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} & \$no\_of\_lines = count(file(\$file)); \tn % Row Count 10 (+ 2) % Row 8 \SetRowColor{LightBackground} subir & \textless{}input type="file" id="docpicker" accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"\textgreater{} \tn % Row Count 15 (+ 5) % Row 9 \SetRowColor{white} & \textless{}input type="file" accept="image/*,.pdf"\textgreater{} \tn % Row Count 17 (+ 2) % Row 10 \SetRowColor{LightBackground} & \textless{}label for="file"\textgreater{}Choose file to upload\textless{}/label\textgreater{} \textless{}input type="file" id="file" name="file" multiple\textgreater{} \tn % Row Count 21 (+ 4) % Row 11 \SetRowColor{white} & accept="image/png" or accept=".png" \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} & \textless{}input type="file" id="image\_uploads" name="image\_uploads" accept=".jpg, .jpeg, .png" multiple\textgreater{} \tn % Row Count 27 (+ 4) % Row 13 \SetRowColor{white} & The selected files' are returned by the element's HTMLInputElement.files property, which is a FileList object containing a list of File objects. The FileList behaves like an array, so you can check its length property to get the number of selected files. \tn % Row Count 36 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.3175 cm} x{12.9525 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{ficheros (cont)}} \tn % Row 14 \SetRowColor{LightBackground} & \textless{}?php \$target\_dir = "uploads/"; \$target\_file = \$target\_dir . basename(\$\_FILES{[}"fileToUpload"{]}{[}"name"{]}); \$uploadOk = 1; \$imageFileType = \seqsplit{strtolower(pathinfo(\$target\_file},PATHINFO\_EXTENSION)); // Check if image file is a actual image or fake image if(isset(\$\_POST{[}"submit"{]})) \{ \$check = getimagesize(\$\_FILES{[}"fileToUpload"{]}{[}"tmp\_name"{]}); if(\$check !== false) \{ echo "File is an image - " . \$check{[}"mime"{]} . "."; \$uploadOk = 1; \} else \{ echo "File is not an image."; \$uploadOk = 0; \} \} \tn % Row Count 18 (+ 18) % Row 15 \SetRowColor{white} & if(\$imageFileType != "jpg" \&\& \$imageFileType != "png" \&\& \$imageFileType != "jpeg" \&\& \$imageFileType != "gif" ) \{ echo "Sorry, only JPG, JPEG, PNG \& GIF files are allowed."; \$uploadOk = 0; \tn % Row Count 25 (+ 7) % Row 16 \SetRowColor{LightBackground} & if \seqsplit{(file\_exists(\$target\_file))} \{ echo "Sorry, file already exists."; \$uploadOk = 0; \} \tn % Row Count 29 (+ 4) % Row 17 \SetRowColor{white} & if (move\_uploaded\_file(\$\_FILES{[}"fileToUpload"{]}{[}"tmp\_name"{]}, \$target\_file)) \{ echo "The file ". basename( \$\_FILES{[}"fileToUpload"{]}{[}"name"{]}). " has been uploaded."; \} else \{ echo "Sorry, there was an error uploading your file."; \} \} \tn % Row Count 38 (+ 9) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.3175 cm} x{12.9525 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{ficheros (cont)}} \tn % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{guardar} \tn % Row Count 1 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{borrar} \tn % Row Count 2 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{obtener log} \tn % Row Count 3 (+ 1) % Row 21 \SetRowColor{white} cerrar stream & fclose(\$f); \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.4902 cm} x{12.7798 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{error}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{personalizados} & if(\$\_REQUEST{[}'ar'{]}=="") throw new Error(); \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.454 cm} x{13.816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{php-ini}} \tn % Row 0 \SetRowColor{LightBackground} & \textless{}? phpinfo(); ?\textgreater{} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} log & en ficheros \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{constantes} & en ficheros \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{htaccess} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} & file\_uploads = On \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} & \textless{}form action="upload.php" method="post" enctype="multipart/form-data"\textgreater{} Select image to upload: \textless{}input type="file" name="fileToUpload" id="fileToUpload"\textgreater{} \textless{}input type="submit" value="Upload Image" name="submit"\textgreater{} \tn % Row Count 13 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.3899 cm} x{10.8801 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Controlador}} \tn % Row 0 \SetRowColor{LightBackground} enviar a misma página & \textless{}form action="index.php" method="POST"\textgreater{} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} name="enviar" en submit & if(isset(\$\_REQUEST{[}'enviar'{]}))\{ \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} & \textless{}input type="text" name="url" placeholder="Nombre"\textgreater{}\textless{}br/\textgreater{} \textless{}input type="number" name="edad" placeholder="Edad"\textgreater{}\textless{}br/\textgreater{} \textless{}input type="number" name="edad" placeholder="Edad"\textgreater{}\textless{}br/\textgreater{} \textless{}input type="submit" name="enviar" value="Registrar"\textgreater{} \tn % Row Count 15 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.454 cm} x{13.816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Excepciones con ficheros}} \tn % Row 0 \SetRowColor{LightBackground} c & if(filter\_var(\$\_REQUEST{[}'email'{]},FILTER\_VALIDATE\_EMAIL)===false) throw new Error\_Email(); \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} c & catch(Error\_Email \$e)\{echo \$e-\textgreater{}errorMessage();\$e-\textgreater{}grabar();\} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} e e & else throw new Exception( \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} e e & \seqsplit{include\_once('Fichero.php');} class Error\_Email extends Exception\{ \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} e e & public function errorMessage()\{ return 'Error \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} e e grabar & \$fichero = new Fichero('error.log'); \$fichero-\textgreater{}write('Email -\textgreater{} Linea:'.\$this-\textgreater{}getLine().'Fichero'.\$this-\textgreater{}getFile()); \tn % Row Count 16 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{finally} \tn % Row Count 17 (+ 1) % Row 7 \SetRowColor{white} f wr & \$f = fopen(\$this-\textgreater{}ruta,'a+'); \tn % Row Count 18 (+ 1) % Row 8 \SetRowColor{LightBackground} & fwrite(\$f,serialize(\$o).PHP\_EOL); \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} f read & \$f = fopen(\$this-\textgreater{}ruta,'r'); while(!feof(\$f))\{ \$u = unserialize(fgets(\$f)); \$a{[}{]} = \$u; \tn % Row Count 25 (+ 5) % Row 10 \SetRowColor{LightBackground} c & for(\$i=0;\$i\textless{}count(\$o)-1;\$i++)\{ \$t.="\textless{}tr\textgreater{}\textless{}td\textgreater{}".\$o{[}\$i{]}-\textgreater{}nombre."\textless{}/td\textgreater{} (\$o)\{ \textless{}td\textgreater{}".\$o{[}\$i{]}-\textgreater{}edad."\textless{}/td\textgreater{} return \$t; \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.454 cm} x{13.816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Excepciones con ficheros (cont)}} \tn % Row 11 \SetRowColor{LightBackground} & \$persona=new Persona(\$nombre,\$edad,\$dni); // CLASE PERSONA \$fichero=new Fichero('persona.txt'); \$fichero-\textgreater{}write(\$persona); echo generarTabla(\$fichero-\textgreater{}read()); \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}