Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/11/2011, 06:20
opzina2
 
Fecha de Ingreso: abril-2009
Mensajes: 46
Antigüedad: 17 años, 4 meses
Puntos: 1
Cual es la forma adecuada

Estoy leyendo sobre clases y objetos y estoy probando, borrando, buscando alternativas.

Armando una clase para crear formularios me plateé diferentes formas de agregar propiedades al tag <form>.

¿Cuál creen que es la mejor opción? Proponen otra?

Código PHP:
<?php

class Form {

    private 
$action = NULL;
    private 
$method = "POST";
    private 
$enctype = NULL;
    
//private $input_type = array();
    //private $input_name;
    
    
    
public function __construct() {
        
        
$this->action;
        
$this->method;
        
$this->enctype;
        
    }
    
    
/*
     * FORMA 1
     */
    
public function set_form($accion = NULL, $encode = NULL, $metodo = "POST") {
        
$this->action = $accion;
        
$this->enctype = $encode;
        
$this->method = $metodo;
    }
    
    public function 
get_form() {
        
        return 
'<form action="'. $this->action .'" method="'. $this->method .'" enctype="'. $this->enctype .'">';
        
    }
    
    
    
/*
     * FORMA 2
     */
    
    
public function create($accion = NULL, $encode = NULL, $metodo = "POST") {
        
        return 
'<form action="'. $this->action = $accion .'" method="'. $this->method = $metodo .'" enctype="'. $this->enctype = $encode .'">';
        
    }
    
    
/*
     * FORMA 3
     */
    
    
protected function read($params = array()) {
        
        
$reading = false;
        foreach (
$params as $property => $value) {
            
//$reading .= " " . $property . "=" . '"' . $value .'"';
            
            
$reading .= " ";
            
$reading .= "$property";
            
$reading .= "=";
            
$reading .= '"' .$value . '"';
            
        }
        
        return 
$reading;
    }
    
    public function 
formCreate($attrs = array()) {
        
        
$form = '<form'. $this->read($attrs) .'>';
        
        return 
$form;
        
    }
    
    
/*
     * FORMA 4 ¿?
     */
    

}

?>