⚠ 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 forum is read-only and soon will be archived. ⚠


yoandry

Member Since 11 Jan 2016
Offline Last Active Jan 29 2016 06:19 PM
-----

Topics I've Started

how I can call a function model within a callback?

12 January 2016 - 04: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;
        }
    }

set relation with two tables

11 January 2016 - 10:58 PM

Sorry I not speak English that is google traslator ;) I hope you can understand me

 

i have that

 

public function orders() {
        try {
            /* This is only for the autocompletion */
            $crud = new grocery_CRUD();
            $crud->set_table('orders');
           
            $crud->set_relation('customer_id', 'customer', 'name');

            $output = $crud->render();
            $this->_main_output($output);
        } catch (Exception $e) {
            show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
        }
    }

 

 

I need to create the orders but only to customers who have a contract and that the date not expired

 

Thanks