print_r($unCd->mostrarDatos());<br> else<br> print("No existe");<br> </div> </div> <h3 > Método de la clase </h3> <?php include_once ("clases/AccesoDatos.php"); include_once ("clases/cd.php"); $unCd =cd::TraerUnCdAnioParamNombre(1,1990); if(isset($unCd->titulo)) print_r($unCd->mostrarDatos()); else print("No existe"); print("<br>"); ?> <a class="btn btn-info" href="index.html">Menu principal</a> </div> </body>
<?php session_start(); if (isset($_SESSION['registrado'])) { require_once "clases/AccesoDatos.php"; require_once "clases/cd.php"; $arrayDeCds = cd::TraerTodoLosCds(); echo "<h2> Bienvenido: " . $_SESSION['registrado'] . "</h2>"; ?> <table class="table" style=" background-color: beige;"> <thead> <tr> <th>Editar</th><th>Borrar</th><th>cantante</th><th>disco</th><th>año</th> </tr> </thead> <tbody> <?php foreach ($arrayDeCds as $cd) { echo "<tr>\n\t\t\t<td><a onclick='EditarCD({$cd->id})' class='btn btn-warning'> <span class='glyphicon glyphicon-pencil'> </span>Editar</a></td>\n\t\t\t<td><a onclick='BorrarCD({$cd->id})' class='btn btn-danger'> <span class='glyphicon glyphicon-trash'> </span> Borrar</a></td>\n\t\t\t<td>{$cd->cantante}</td>\n\t\t\t<td>{$cd->titulo}</td>\n\t\t\t<td>{$cd->año}</td>\n\t\t</tr> "; } ?> </tbody> </table> <?php } else { echo "<h4 class='widgettitle'>No estas registrado</h4>"; }
<?php session_start(); if (validadora::validarSesionActual()) { require_once "clases/AccesoDatos.php"; require_once "clases/cd.php"; $estadisticas = cd::TraerEstadisticas(); echo "<h2> Bienvenido: " . $_SESSION['registrado'] . "</h2>"; ?> <div id="grillaEstadistica" style="min-width: 310px; height: 400px; margin: 0 auto"> </div> <table class="table" id="tablaEstadistica" style=" background-color: beige;display:none;"> <thead> <tr> <th>Cantante</th><th>CantidadCD</th> </tr> </thead> <tbody> <?php foreach ($estadisticas as $row) { echo "<tr>\n\t\t\t<td>" . $row["cantante"] . "</td>\n\t\t\t<td>" . $row["cantidadCD"] . "</td>\n\t\t</tr> "; } ?> </tbody> </table> <?php } else {
include "partes/formGrilla.php"; break; case 'MostarLogin': include "partes/formLogin.php"; break; case 'MostrarFormAlta': include "partes/formCd.php"; break; case 'BorrarCD': $cd = new cd(); $cd->id = $_POST['id']; $cantidad = $cd->BorrarCd(); echo $cantidad; break; case 'GuardarCD': $cd = new cd(); $cd->id = $_POST['id']; $cd->cantante = $_POST['cantante']; $cd->titulo = $_POST['titulo']; $cd->año = $_POST['anio']; $cantidad = $cd->GuardarCD(); echo $cantidad; break; case 'TraerCD': $cd = cd::TraerUnCd($_POST['id']); echo json_encode($cd); break; default: # code... break; }
{ protected $cdInfo = array(); public function addSong($song) { $this->cdInfo[$song] = $song; } public function playMp3($song) { return $this->cdInfo[$song] . '.mp3'; } public function playMp4($song) { return $this->cdInfo[$song] . '.mp4'; } } $oldCd = new cd(); $oldCd->addSong("1"); $oldCd->addSong("2"); $oldCd->addSong("3"); $type = 'mp3'; if ($type == 'mp3') { echo $oldCd->playMp3(1); } else { echo $oldCd->playMp4(2); } //委托模式-去除核心对象中的判决和复杂的功能性 //改进cd类 class cdDelegate { protected $cdInfo = array(); public function addSong($song)