⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

how I can call a function model within a callback?



yoandry

yoandry
  • profile picture
  • Member

Posted 12 January 2016 - 16:00 PM

$crud->callback_before_insert(array($this, 'val_orden'));

 

----------------------------------------------------------------------------

function val_orden($post_array) {
        $sql=  "SELECT Count(cliente.nombre) FROM contrato INNER JOIN cliente ON contrato.cliente_id = cliente.id WHERE contrato.fecha_fin > now() AND contrato.cliente_id =". $post_array['cliente'];
        if (mysql_query($sql) > 0) {
            return $post_array;
        } else {
            return false;
        }
    }

*******************************************************************************

or

 

in the model

public function get_empresa($empresa) {
        $query = $this->db->query("SELECT
Count(cliente.nombre)
FROM
contrato
INNER JOIN cliente ON contrato.cliente_id = cliente.id
WHERE
contrato.fecha_fin > now() AND
contrato.cliente_id = $empresa ");
        return $query->result();
    }

$crud->callback_before_insert(array($this, 'val_orden'));

function val_orden($post_array) {
        if ($this->model->get_empresa($post_array[cliente]) > 0) {
            return $post_array;
        } else {
            return false;
        }
    }