Guest User

Untitled

a guest
May 16th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. class Application_Model_Noticias extends Application_Model_Abstract
  4. {
  5.  
  6.   protected static $_dbTable_class = 'Application_Model_DbTable_Noticias';
  7.  
  8.   public function __construct()
  9.   {
  10.     $options['dbTable'] = Application_Model_Noticias::$_dbTable_class;
  11.     parent::__construct($options);
  12.     $this->_campos = $this->_dbTable->info(Zend_Db_Table::COLS);
  13.     return $this;
  14.   }
  15.  
  16.   public static function save( $params )
  17.   {
  18.       $validate = self::validate( $params ) ;
  19.       if( $validate === true ):
  20.         try
  21.         {
  22.           $dbTable = new self::$_dbTable_class;
  23.           $row = $dbTable->createRow( $params );
  24.           $return = $row->save();
  25.           return $return;
  26.         } catch (Exception $e)
  27.         {
  28.           throw new Exception( $e->getMessage(), $e->getCode() );
  29.           die();
  30.         }
  31.       else:
  32.         return $validate;
  33.       endif;
  34.    
  35.   }
  36.  
  37.   protected static function validate( $params )
  38.   {
  39.     $form = new Teaser_Forms_Noticias();
  40.     if (!$form->isValid( $params )):
  41.       $messages = $form->getMessages();
  42.       $return['type'] = 'error';
  43.       $return['messagesError'] = $form->addErrorMessages( $messages );
  44.       return $return;
  45.     endif;
  46.     return true;
  47.   }
  48.  
  49. }
Add Comment
Please, Sign In to add comment