Olá,
Alguém pode me ajudar nesse código abaixo?
(Can anyone help me with this code below?)
Problema: Preciso tratar alguns dados antes de submete-los ao banco de dados.
Queria também, só para fim de organização do código, separar as ações dentro de escopos diferentes, exemplo:
(Problem: I need to handle some data before submitting it to the database.
I also wanted, for the purpose of organizing the code, to separate actions within different scopes, for example:)
if($state === 'list'){
//process any fields before list.
$output = $crud->render(); // not allowed here?
$this->_example_output($output); // not allowed here?
}
if($state === 'add'){
//process any fields before add.
$output = $crud->render(); // not allowed here?
$this->_example_output($output); // not allowed here?
}
if($state === 'edit'){
//process any fields before edit.
$output = $crud->render(); // not allowed here?
$this->_example_output($output); // not allowed here?
}
if($state === 'insert'){
//process any fields before insert.
$output = $crud->render(); // not allowed here?
$this->_example_output($output); // not allowed here?
}
Segue um pedaço do meu código.
Here's a little of my code.
public function index(){
$crud = new grocery_CRUD();
echo $state = $crud->getState();
$state_info = $crud->getStateInfo();
if($state === 'add'){
$crud->unset_jquery();
$crud->set_theme('datatables');
$crud->set_subject('Adicionar Proximo Sorteio');
$crud->unset_add_fields('desc_rodada2','foto_premio1','foto_premio2', 'foto_premio3', 'foto_premio4');
$crud->fields('data','n_susep', 'desc_rodada', 'separador', 'desc_premio1', 'desc_premio2', 'desc_premio3', 'desc_premio4', 'img_cautela', 'proxExtracao');
$crud->field_type('data', 'date');
/// Here not Show :(
$crud->callback_before_insert(function ($post_array) {
echo "<script>alert('callback_before_insert')</script>";
return $post_array;
});
}
/// Here not Show :(
elseif($state === 'insert'){
echo "ENTREI";
//die();
}
$output = $crud->render();
$this->_example_output($output);
}
public function _example_output($output = null){
.....
}
Can anyone help me with this code below?
