Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/04/2007, 08:14
GPS
 
Fecha de Ingreso: diciembre-2003
Ubicación: Montevideo, Uruguay
Mensajes: 110
Antigüedad: 20 años, 5 meses
Puntos: 0
Pregunta Primer intento con POO, espero criticas

Estuve leyendo "manuales" en internet de POO para php y quiero intentar hacer mi primer aplicación.

Me gustaría saber si estoy encarando bien el concepto de este tipo de programación, o si tengo un error de concepto de como debería funcionar esto

Aquí les dejo el código de una class llamada secciones, que es la que se encargaria del tratamentiento de las secciones de mi aplicación

Saludos y gracias

Código:
<?php

class seccion {
	
	var $id;
	var $titulo;
	var $descripcion;
	var $estado;
	var $mensaje;
	
	function seccion() {
	 	$this->id = '';
	 	$this->titulo = '';
	 	$this->descripcion = '';
	 	$this->estado = 1;
	 	$this->mensaje = '';
	}
	
	//CARGAMOS TITULO
	function setTitulo($titulo) {
		$this->titulo = make_safe($titulo);	
	}
	
	//CARGAMOS DESCRIPCION
	function setDescripcion($descripcion) {
		$this->descripcion = make_safe($descripcion);
	}
	
	//AGREGAR SECCION $this->titulo, $this->descripcion 
	function agregar() {	 
	 	$agregar = true;
	 	
	 	if (trim($this->titulo) == '') {
			$this->mensaje.= "Debe ingresar un título. ";
			$agregar = false;
		}
		
		if (trim($this->descripcion) == '') {
			$this->mensaje.= "Debe ingresar una descripcion. ";
			$agregar = false;
		}
		
		if ($agregar) {
			$sql = "insert into secciones (titulo, descripcion, estado) ";
			$sql.= "values ('$this->titulo', '$this->descripcion', '$this->estado')";
			$res = mysql_query($sql);
			
			if ($res) {
				$this->mensaje.= "La seccion se agrego exitosamente";
			} else {
				$this->mensaje.= "La seccion no se puedo agregar correctamente";
			}	
		}		
	}
	
	//GUARDO EN LA BD LA NOTICIA EDITADA
	function actualizar() {
		$sql = "update secciones set titulo = '$this->titulo', descripcion = '$this->descripcion' where id = $this->id";
		mysql_query($sql);
	}
	
	//SELECCIONAR $this->id SECCION (Guardo resultados en $this->titulo y $this->descripcion)
	function seleccionar() {
	 	if (trim($this->id) == '') {
			$this->mensaje = "No paso parametro para seleccionar noticia";
		} else {
			$sql = "select titulo, descripcion from secciones where id = $this->id and estado = 1";
			$res = mysql_query($sql);
			$row = mysql_fetch_array($res);
			
			$this->titulo = $row['titulo'];
			$this->descripcion = $row['descripcion'];
		}
	}
	
}

?>