Ver Mensaje Individual
  #11 (permalink)  
Antiguo 23/12/2012, 18:31
underwebinfo
 
Fecha de Ingreso: septiembre-2012
Ubicación: Buenos aires
Mensajes: 110
Antigüedad: 11 años, 6 meses
Puntos: 9
Respuesta: Class var en eval

La clase completa.

Código PHP:
Ver original
  1. # --- Paginador
  2. class Cm_Paginador{
  3.    
  4.     # --- Configuracion
  5.     var $Posicion,$Botones,$Base,$Article,$Order,$Mysql,$Query,$Exect,$Cant,$Paginas,$Comming,$Consulta,$Estructura;
  6.    
  7.     # --- Mysql
  8.     public function _Mysql($Mysql,$base,$article,$orden,$Posicion){
  9.        
  10.         # --- Mysql
  11.         $this->Base  = $base;
  12.         $this->Order = $orden;
  13.         $this->Article = $article;
  14.         $this->Mysql    = $Mysql;
  15.         $this->Posicion = $Posicion;
  16.         $this->Mysql->Conectar();
  17.         $this->Query = "SELECT * FROM ".($this->Base);
  18.         $this->Exect = $this->Mysql->Consulta($this->Query);
  19.        
  20.         # --- Condicionales
  21.         $this->Cant     = $this->Mysql->Reg_Num($this->Exect);
  22.         $this->Paginas  = ceil($this->Cant/$this->Article);
  23.         $this->Comming  = $this->Article*$this->Posicion;
  24.         $Desde          = $this->Posicion*$this->Paginas;
  25.    
  26.         # --- Consulta
  27.         $this->Consulta = $this->Mysql->Consulta($this->Query.' ORDER BY id '.$orden.' LIMIT '.$Desde.' , '.$this->Cant);
  28.    
  29.     }
  30.    
  31.     # --- Estructura
  32.     public function _Estructure($estructure){
  33.        
  34.         $this->Estructura = $estructure;
  35.        
  36.     }
  37.    
  38.     # --- Devolucion
  39.     public function _Devolucion(){
  40.        
  41.         $str = $this->Estructura;
  42.                
  43.         while($Campo = $this->Mysql->Assoc($this->Consulta)){
  44.                        
  45.             foreach($Campo as $clave => $valor) {
  46.                    
  47.                 $str = str_replace('{'.$clave.'}',$valor,$str);
  48.                
  49.                
  50.             }
  51.            
  52.             echo $str;
  53.  
  54.         }
  55.  
  56.     }
  57.    
  58.     # --- Navegacion
  59.     public function _Navegacion($botones){
  60.        
  61.         # Vars
  62.         $this->Botones = $botones;
  63.        
  64.         if(($this->Botones)>=3){
  65.            
  66.             // next
  67.             if(($this->Posicion)>1 && ($this->Paginas)>1){
  68.                
  69.                 echo '<input type="button" onClick="Paginacion('.(($this-Posicion)-1).')" value="next">';
  70.                
  71.             }
  72.            
  73.             // numbers
  74.             for($i = 1;$i<$this->Botones;$i++){
  75.            
  76.                 if($i<$this->Paginas){
  77.                    
  78.                     echo '<input type="button" value="'.$i.'" onClick="Paginacion('.$i.')">';
  79.                        
  80.                 }
  81.            
  82.             }
  83.            
  84.             // prev
  85.             if(($this->Posicion)<($this->Paginas)){
  86.                
  87.                 echo '<input type="button" onClick="Paginacion('.(($this->Posicion)+1).')" value="prev">';
  88.                
  89.             }
  90.    
  91.         }
  92.        
  93.         if(($this->Botones)<=2){
  94.        
  95.                    
  96.             // next
  97.             if(($this->Posicion)>1 && ($this->Paginas)>1){
  98.                
  99.                 echo '<input type="button" onClick="Paginacion('.(($this->Posicion)-1).')" value="next">';
  100.                    
  101.             }
  102.    
  103.             // prev
  104.             if(($this->Posicion)<($this->Paginas)){
  105.                    
  106.                 echo '<input type="button" onClick="Paginacion('.(($this->Posicion)+1).')" value="prev">';
  107.                    
  108.             }
  109.                            
  110.         }
  111.        
  112.     }
  113.    
  114. }


Su forma de uso:
Código PHP:
Ver original
  1. # --- Framework
  2.     include("../../Include/Cm_Framework.php");
  3.  
  4.     # --- Posicion
  5.     if(isset($_POST['Page']) && $_POST['Page']==''){
  6.        
  7.         $Posicion = intval($_POST['Page']);
  8.    
  9.     }else{
  10.        
  11.         $Posicion = 1;
  12.  
  13.     }
  14.  
  15.     # --- Configuracion
  16.     $Paginador  = new Cm_Paginador;
  17.     $Paginador->_Mysql(new Cm_mysql,'Album',5,'DESC',1);
  18.  
  19.     # --- Estructura
  20.     $Estructure = '<li><article class="Info"><h1><img src="Content/Albums/{Slug}/{Caratula}">{Titulo}</h1><p>{Pie}</p></article><article class="Multimedia" id="Album_{id}"><a href="http://Naylafernandez.com.ar/Album/{Slug}/" target="new" class="Ver" title="Ver Album"></a> <input type="button" title="Agregar Fotos" class="Agregar"> <input type="button" title="Editar Album" class="Editar"> <input type="button" title="Eliminar Album" class="Eliminar"></article></li>';
  21.     $Paginador->_Estructure($Estructure);
  22.      
  23.     # --- Devolucion
  24.     $Paginador->_Devolucion();
  25.    
  26.     # --- Paginacion
  27.     $Paginador->_Navegacion(5);




Lo que no funciona:

Código PHP:
Ver original
  1. $str = $this->Estructura;
  2.                
  3.         while($Campo = $this->Mysql->Assoc($this->Consulta)){
  4.                        
  5.             foreach($Campo as $clave => $valor) {
  6.                    
  7.                 $str = str_replace('{'.$clave.'}',$valor,$str);
  8.                
  9.                
  10.             }
  11.            
  12.             echo $str;
  13.  
  14.         }