Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. /*VISTA*/
  2. <?php
  3.     Load::lib('fpdf');
  4.  
  5.     $pdf=new FPDF();
  6.     $pdf->AliasNbPages();
  7.     $pdf->AddPage();
  8.     $pdf->SetFont('Arial','B',20);
  9.     foreach ($municipio as $var){
  10.         $pdf->Cell(209,18,$var->nombre,0,0,'C');
  11.         foreach ($var->getParroquia() as $parroquia){
  12.         $pdf->Cell(210,18,$parroquia->nombre,0,0,'C')
  13.         }
  14.         $pdf->ln();
  15.     }
  16.     $pdf->Output();
  17. ?>
  18.  
  19. /*CONTROLADOR*/
  20.  
  21. <?php
  22.     class PdfController extends ApplicationController {
  23.  
  24.         public function index(){
  25.            
  26.         }
  27.        
  28.         public function reporte(){
  29.             $this->set_response('view');
  30.             $municipio = new Municipio();
  31.             $this->municipio = $municipio->find();
  32.         }
  33.  
  34.     }
  35. ?>
  36.  
  37. /* INDEX*/
  38.  
  39. <? View::content(); ?>
  40. <?php echo link_to('pdf/reporte', 'Generar PDF')?>
  41.  
  42. /*Modelos */
  43. <?php
  44. /*
  45.  * Created on 26/10/2010
  46.  *
  47.  * To change the template for this generated file go to
  48.  * Window - Preferences - PHPeclipse - PHP - Code Templates
  49.  */
  50.    
  51.     class Municipio extends ActiveRecord {
  52.      
  53.      public function initialize(){
  54.         $this->has_many('parroquia');
  55.        
  56.      }
  57.      
  58.      public function getMunicipio($page, $ppage=20){
  59.         return $this->paginate("page: $page", "per_page: $ppage","order: nombre");
  60.      }
  61.      
  62.      //Validacion antes de crear un registro
  63.      public function before_validation_on_create() {   
  64.         $this->validates_uniqueness_of('nombre','message: El nombre ya existe');   
  65.      }
  66. public function validaEliminarMunicipio($id){
  67.         $parroquia = new Parroquia();
  68.         if($parroquia->find_first("municipio_id =".$id)){
  69.             Flash::error("No se puede eliminar este registro ya que esta relacionado con al menos una Parroquia. ");
  70.             Router::route_to('action: index', 'id: 1');
  71.             return true;
  72.         }
  73.         else{
  74.             return false;
  75.         }      
  76.      }
  77.     }  
  78. ?>
  79. /*MODELOS***/
  80. <?php
  81. /*
  82.  * Created on 26/10/2010
  83.  *
  84.  * To change the template for this generated file go to
  85.  * Window - Preferences - PHPeclipse - PHP - Code Templates
  86.  */
  87.  class Parroquia extends ActiveRecord {
  88.        
  89.     public function initialize(){
  90.         $this->belongs_to('municipio');
  91.         $this->has_many('ficha');
  92.      }
  93.      public function getParroquia($page, $ppage=20){
  94.         return $this->paginate("page: $page", "per_page: $ppage","order: nombre");
  95.      }
  96.  
  97.      //Validacion antes de crear un registro
  98.      public function before_validation_on_create() {   
  99.      // $this->validates_uniqueness_of('nombre','message: El nombre ya existe');   
  100.      }
  101.      
  102.      
  103.      //Busca los estados perteneciente a un pais ($categoriadelito_id)
  104.      public function buscarPorMunicipio($municipio_id){
  105.         return $this->find("municipio_id = $municipio_id", 'order: nombre');
  106.     }
  107.    
  108.      public function validaEliminarParroquia($id){
  109.         $ficha = new Ficha();
  110.        
  111.         if($ficha->find_first("parroquia_id=".$id)){
  112.             Flash::error("No se puede eliminar este registro ya que esta relacionado con al menos un Municipio. ");
  113.             Router::route_to('action: index', 'id: 1');
  114.             return true;
  115.         }
  116.         else{
  117.             return false;
  118.         }      
  119.      }    
  120. }
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement