Phalcon -¿BeforeSave not receive data before saving? : I want to validate before saving if the variable "$ CONT_CEDULA" meets the requirements otherwise not be saved. But when saving is as if the variable "$ CONT_CEDULA" not send data. I want to know if I'm doing well or some other event or function. The "echo" Initial no data

> Blockquote

    public function beforeSave() {
    
            echo $this->$CONT_CEDULA;
            switch (strlen($this->$CONT_CEDULA)) {
            case 10:
                return validarCI($this->$CONT_CEDULA);
                break;
            case 13:
                return validarRUC($this->$CONT_CEDULA);
                break;
            default:
               echo "Numero de caracteres invalidos"  ;
                return FALSE;
        }
    
    <pre>
     <?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->setSchema("SPOLS");
        $this->hasMany('CONT_CODIGO', 'SPMREFERENCIA', 'CONT_CODIGO', array('alias' => 'SPMREFERENCIA'));
        $this->hasMany('CONT_CODIGO', 'SPTDETALLE', 'CONT_CODIGO', array('alias' => 'SPTDETALLE'));
        $this->hasMany('CONT_CODIGO', 'SPTENCABEZADO', 'CONT_CODIGO', array('alias' => '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 < 1 || (int) $intProvincia > 23)
            return FALSE;
        if ((int) $intTercero == 7 || (int) $intTercero == 8)
            return FALSE;
        for ($indice = 0; $indice < 9; $indice++) {
            //echo $strOriginal[$indice],'</br>';
            switch ($indice) {
                case 0:
                case 2:
                case 4:
                case 6:
                case 8:
                    $arrProducto[$indice] = $strOriginal[$indice] * 2;
                    if ($arrProducto[$indice] >= 10)
                        $arrProducto[$indice] -= 9;
                    //echo $arrProducto[$indice],'</br>';
                    break;
                case 1:
                case 3:
                case 5:
                case 7:
                    $arrProducto[$indice] = $strOriginal[$indice] * 1;
                    if ($arrProducto[$indice] >= 10)
                        $arrProducto[$indice] -= 9;
                    //echo $arrProducto[$indice],'</br>';
                    break;
            }
        }
        foreach ($arrProducto as $indice => $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 < 1 || (int) $intProvincia > 23)
            return FALSE;
        if ((int) $intTercero != 6 && (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 < 9; $indice++) {
                //echo $strOriginal[$indice],'</br>';
                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 < 9; $indice++) {
                //echo $strOriginal[$indice],'</br>';
                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 => $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->$CONT_CEDULA;
        switch (strlen($this->$CONT_CEDULA)) {
            case 10:
                return validarCI($this->$CONT_CEDULA);
                break;
            case 13:
                return validarRUC($this->$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);
    }
    
    </pre>

