title: Phalcon BeforeSave not receiving data before saving?
body: <p>Before I save my model, I would like to check if <code>$ CONT_CEDULA</code> meets the requirements. If not, then don't save. But when saving, it is as if the variable <code>$ CONT_CEDULA</code> hasn't got any data. I want to know if I'm doing well or need some other event or function. Also, the <code>echo</code> outputs no data.</p>
  
  <p><strong>beforeSave method</strong></p>
  
  <pre><code>public function beforeSave() {
  
          echo $this-&gt;$CONT_CEDULA;
          switch (strlen($this-&gt;$CONT_CEDULA)) {
          case 10:
              return validarCI($this-&gt;$CONT_CEDULA);
              break;
          case 13:
              return validarRUC($this-&gt;$CONT_CEDULA);
              break;
          default:
             echo "Numero de caracteres invalidos"  ;
              return FALSE;
      }
  </code></pre>
  
  <p><strong>SpmContacto model</strong></p>
  
  <pre><code> &lt;?php
  
  class SpmContacto extends \Phalcon\Mvc\Model {
  
  public $CONT_CODIGO;
  public $CONT_CEDULA;
  public $CONT_RUCIDE;
  public $CONT_NOMBRE;
  public $CON_ESTADO;
  public $CONT_TELEFO;
  public $CONT_DIRECC;
  public $CONT_AREA;
  public $CONT_CARGO;
  public $CONT_TIPOXX;
  public $CONT_EMAIL;
  public $CONT_USUARIO;
  public $CONT_CLAVE;
  public $CONT_CLAVEE;
  public $CONT_FECNACI;
  public $CONT_FECINSC;
  public $CONT_TIPOCODIGO;
  
  /**
   * Initialize method for model.
   */
  public function initialize() {
      $this-&gt;setSchema("SPOLS");
      $this-&gt;hasMany('CONT_CODIGO', 'SPMREFERENCIA', 'CONT_CODIGO', array('alias' =&gt; 'SPMREFERENCIA'));
      $this-&gt;hasMany('CONT_CODIGO', 'SPTDETALLE', 'CONT_CODIGO', array('alias' =&gt; 'SPTDETALLE'));
      $this-&gt;hasMany('CONT_CODIGO', 'SPTENCABEZADO', 'CONT_CODIGO', array('alias' =&gt; 'SPTENCABEZADO'));
  }
  
  function validarCI($strCedula) {
      $suma = 0;
      $strOriginal = $strCedula;
      $intProvincia = substr($strCedula, 0, 2);
      $intTercero = $strCedula[2];
      $intUltimo = $strCedula[9];
      if (!settype($strCedula, "float"))
          return FALSE;
      if ((int) $intProvincia &lt; 1 || (int) $intProvincia &gt; 23)
          return FALSE;
      if ((int) $intTercero == 7 || (int) $intTercero == 8)
          return FALSE;
      for ($indice = 0; $indice &lt; 9; $indice++) {
          //echo $strOriginal[$indice],'&lt;/br&gt;';
          switch ($indice) {
              case 0:
              case 2:
              case 4:
              case 6:
              case 8:
                  $arrProducto[$indice] = $strOriginal[$indice] * 2;
                  if ($arrProducto[$indice] &gt;= 10)
                      $arrProducto[$indice] -= 9;
                  //echo $arrProducto[$indice],'&lt;/br&gt;';
                  break;
              case 1:
              case 3:
              case 5:
              case 7:
                  $arrProducto[$indice] = $strOriginal[$indice] * 1;
                  if ($arrProducto[$indice] &gt;= 10)
                      $arrProducto[$indice] -= 9;
                  //echo $arrProducto[$indice],'&lt;/br&gt;';
                  break;
          }
      }
      foreach ($arrProducto as $indice =&gt; $producto)
          $suma += $producto;
      $residuo = $suma % 10;
      $intVerificador = $residuo == 0 ? 0 : 10 - $residuo;
      return ($intVerificador == $intUltimo ? TRUE : FALSE);
  }
  
  function validarRUC($strRUC) {
      if (strlen($strRUC) != 13)
          return FALSE;
      $suma = 0;
      $strOriginal = $strRUC;
      $intProvincia = substr($strRUC, 0, 2);
      $intTercero = $strRUC[2];
      if (!settype($strRUC, "float"))
          return FALSE;
      if ((int) $intProvincia &lt; 1 || (int) $intProvincia &gt; 23)
          return FALSE;
      if ((int) $intTercero != 6 &amp;&amp; (int) $intTercero != 9) {
          if (substr($strRUC, 10, 3) == '001')
              return validarCI(substr($strRUC, 0, 10));
          return FALSE;
      }
      if ((int) $intTercero == 6) {
          $intUltimo = $strOriginal[8];
          for ($indice = 0; $indice &lt; 9; $indice++) {
              //echo $strOriginal[$indice],'&lt;/br&gt;';
              switch ($indice) {
                  case 0:
                      $arrProducto[$indice] = $strOriginal[$indice] * 3;
                      break;
                  case 1:
                      $arrProducto[$indice] = $strOriginal[$indice] * 2;
                      break;
                  case 2:
                      $arrProducto[$indice] = $strOriginal[$indice] * 7;
                      break;
                  case 3:
                      $arrProducto[$indice] = $strOriginal[$indice] * 6;
                      break;
                  case 4:
                      $arrProducto[$indice] = $strOriginal[$indice] * 5;
                      break;
                  case 5:
                      $arrProducto[$indice] = $strOriginal[$indice] * 4;
                      break;
                  case 6:
                      $arrProducto[$indice] = $strOriginal[$indice] * 3;
                      break;
                  case 7:
                      $arrProducto[$indice] = $strOriginal[$indice] * 2;
                      break;
                  case 8:
                      $arrProducto[$indice] = 0;
                      break;
              }
          }
      } else {
          $intUltimo = $strOriginal[9];
          for ($indice = 0; $indice &lt; 9; $indice++) {
              //echo $strOriginal[$indice],'&lt;/br&gt;';
              switch ($indice) {
                  case 0:
                      $arrProducto[$indice] = $strOriginal[$indice] * 4;
                      break;
                  case 1:
                      $arrProducto[$indice] = $strOriginal[$indice] * 3;
                      break;
                  case 2:
                      $arrProducto[$indice] = $strOriginal[$indice] * 2;
                      break;
                  case 3:
                      $arrProducto[$indice] = $strOriginal[$indice] * 7;
                      break;
                  case 4:
                      $arrProducto[$indice] = $strOriginal[$indice] * 6;
                      break;
                  case 5:
                      $arrProducto[$indice] = $strOriginal[$indice] * 5;
                      break;
                  case 6:
                      $arrProducto[$indice] = $strOriginal[$indice] * 4;
                      break;
                  case 7:
                      $arrProducto[$indice] = $strOriginal[$indice] * 3;
                      break;
                  case 8:
                      $arrProducto[$indice] = $strOriginal[$indice] * 2;
                      break;
              }
          }
      }
      foreach ($arrProducto as $indice =&gt; $producto)
          $suma += $producto;
      $residuo = $suma % 11;
      $intVerificador = $residuo == 0 ? 0 : 11 - $residuo;
      //echo "$intVerificador == $intUltimo";
      return ($intVerificador == $intUltimo ? TRUE : FALSE);
  }
  
  function validarID($strId) {
      switch (strlen($strId)) {
          case 10:
              return validarCI($strId);
              break;
          case 13:
              return validarRUC($strId);
              break;
          default:
  
              return FALSE;
      }
  }
  
  public function beforeSave() {
  
      echo $this-&gt;$CONT_CEDULA;
      switch (strlen($this-&gt;$CONT_CEDULA)) {
          case 10:
              return validarCI($this-&gt;$CONT_CEDULA);
              break;
          case 13:
              return validarRUC($this-&gt;$CONT_CEDULA);
              break;
          default:
             echo "Numero de caracteres invalidos";
           return FALSE;
      }
  
       //echo $op;
  }
  
  public function getSource() {
      return 'SPM_CONTACTO';
  }
  
  public static function find($parameters = null) {
      return parent::find($parameters);
  }
  
  public static function findFirst($parameters = null) {
      return parent::findFirst($parameters);
  }
  </code></pre>