Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/12/2010, 10:29
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Conexion PDO con patron Registro

No, el patrón Registry, no se implementa así, te recomiendo veas ejemplos en internet, algo muy simple sería asi:
Código PHP:
Ver original
  1. class Registry {
  2.     private $_cache;
  3.    
  4.     public function __construct() {
  5.         $this->_cache = array();
  6.     }
  7.     public function set($key, &$item) {
  8.         $this->_cache[$key] = &$item;
  9.     }
  10.     public function get($key) {
  11.         return $this->_cache[$key];
  12.     }
  13.     public function has($key) {
  14.         return ($this->get($key) !== null);
  15.     }
  16. }

Y lo usas como:
Código PHP:
Ver original
  1. $Registry = new Registry();
  2. if (!$Registry->has('conexion')) {
  3.       $Registry->set('conexion', $conexion);
  4. }
  5. // Mas adelante
  6. $conexion = $Registry->get('conexion');

Saludos.

Última edición por GatorV; 16/12/2010 a las 14:54