Hi,
I created an action with add_action and it must redirect to add form, passing generated data from the row primary key to some of the fields. Here is how I did it:
$this->grocery_crud->set_table($this->table); [...] //set the action $this->grocery_crud->add_action('Add', base_url() . 'assets/_templates/backend/images/external_link.gif' , 'planocontas/addAccount', 'sub-menu-icon'); $this->grocery_crud->unset_jquery(); $output = $this->grocery_crud->render(); //load the view $this->template->load('_templates/backend/backend_default', 'default_view', $output); }
The action function:
public function addAccount($primary_key) { try { //get info from $primary_key $row = $this->plano_contas->findByPk($primary_key); if ($row != null) { //do stuff $id_conta = $this->plano_contas->_geraProximaSubConta($row->parent_id); //uses callback_add_field to pass the info $this->grocery_crud->callback_add_field('id_conta', function () { return '<input type="text" maxlength="50" value="' . $id_conta . '" name="natureza">'; }); [...] } else { [...] } $this->grocery_crud->set_table($this->db->table_prefix . $this->table); $this->grocery_crud->unset_list(); $this->grocery_crud->unset_edit(); $this->grocery_crud->render(); //as I did [...]unset_list() I get an exception on render() so i'm redirected here: } catch (Exception $e) { if ($e->getCode() == 14) { //The 14 is the code of the "You don't have permissions" err //or on grocery CRUD.] //here I redirect to the add form, it opens correctly, but the callback_add_field is never 'executed' and all the fields come blank redirect(site_url(strtolower(__CLASS__) . '/index/add/')); } else { show_error($e->getMessage()); return false; } } }
I must be doing something wrong, can you help me? How can I acomplish this?
Second thing: at add action, on the style class, i have a class of my own, but the name concats with ' crud-action' and it doesn't work. Is it possible to use class style that is not from grocery crud's theme?
I really need to pass the info for add form on the action click. Please help me! Thank you very much.
Ps.: when I click the grocery 'Add' button, the form has to come clean, the information is generated and passed only when the action is clicked.