Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created April 2, 2018 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/2184a14e340c85cc116e2cfe048d342c to your computer and use it in GitHub Desktop.
Save phpfiddle/2184a14e340c85cc116e2cfe048d342c to your computer and use it in GitHub Desktop.
[ Posted by Kapry ] php pdo script ejemplo 1
<?php
//Autor: Walter Sanchez
//Fecha: 02 abril 2018
class html{
private $script=null;
public function cabeza($tituloPagina="Sin Titulo"){
$inicio = '<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title>'.$tituloPagina.'</title>';
$cierreHead = '</head>';
// compruebo que la propiedad script no sea nula es decir que se haya seteado.
// si tiene algo inserta el tag HTML <script></script> con su javasdcript en su interior
// si no tiene nada no se imprime el tag HTML <script></script>
if(!is_null( $this->script)){
$scriptJS = $this->getScriptJS();
echo $inicio.$scriptJS.$cierreHead;
}
}
public function abrirCuerpo(){
echo "<body>";
}
public function cerrarCuerpo(){
echo "</body>";
}
public function pie(){
echo "</html>";
}
public function setScriptJS($scriptObj){
// a la propiedad script selo setea con el valor obtenido
$this->script=$scriptObj;
}
private function getScriptJS(){
// Crea el Tag '<script> con el codigo de javascript seteado
$scriptJSapertura = '<script>';
$scriptJSCierre = '</script>';
$scriptJS = $scriptJSapertura.$this->script.$scriptJSCierre;
return $scriptJS;
}
}// Fin de la Class: html
class MiClase
{
private $nombreObjeto = '';
public function __construct()
{
echo "se creo el objeto".get_called_class() ."<br>";
}
public function setNombre($nombre){
$this->nombreObjeto= $nombre;
}
public function getNombre(){
return $this->nombreObjeto;
}
}// Fin de la Class: MiClase
//html
$objetohtml = new html();
// insertar codigo javascript
$objetohtml->setScriptJS("alert('Esto es un alerta de Javascript.')");
$objetohtml->cabeza('POO PHP');
$objetohtml->abrirCuerpo();
// imprimir nombres
$miObjeto = new MiClase();
$miObjeto->setNombre('Walter');
echo $miObjeto->getNombre().'<br>';
$miObjeto2 = new MiClase();
$miObjeto2->setNombre('Claudio');
echo $miObjeto2->getNombre();
// html
$objetohtml->cerrarCuerpo();
$objetohtml->pie();
//Tarea
//Crear Funcion que modifique la propiedad $NombreObjeto
//Convertir la propiedad "$nombreObjeto" a privada
//Crear 5 diferentes objetos con diferente nombre y mostrar los nombres de cada uno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment