Welcome Guest, Not a member yet? Register   Sign In
grocery crud / Ci 3
#1

hi guys!!

i have value in $id.
 how to pass the parameter $id

$user = $this->ion_auth->user()->row();
$id = $user->id;


public function testeveiculos()
    {
   
            $crud = new grocery_CRUD();
      $crud->columns('id', 'marca','modelo','cor','placa');
      //$crud->collumns('id', $id)???

      ......


}

how would it be??
Reply
#2

You should use where if you want to limit the results:
https://www.grocerycrud.com/documentatio...ions/where
Reply
#3

(06-18-2018, 11:54 PM)jreklund Wrote: You should use where if you want to limit the results:
https://www.grocerycrud.com/documentatio...ions/where

my problem is need id user together with the remaining do form.

//Get user Ion auth
$user = $this->ion_auth->user()->row();
$id = $user->id;

and a function GC

public function testeveiculos()
    {
          
            $crud = new grocery_CRUD();
            $crud->set_table('veiculos');
            $crud->columns('marca','modelo','cor','placa');
            $crud->display_as('marca','modelo');
            $crud->unset_fields('id_user');
            $crud->set_subject('NOVO VEICULO');
            $output = $crud->render();
            $this->_example_output($output);
    }

 I need  $id in  esteveiculos()
 understood??

Sorry my english!!
Reply
#4

(This post was last modified: 06-19-2018, 08:02 AM by jreklund. Edit Reason: Added some references to docs )

You want veiculos to insert the current logged in user id?

https://www.grocerycrud.com/documentatio...ore_insert
https://www.grocerycrud.com/documentatio...ore_update
https://www.grocerycrud.com/documentatio...ible-field

PHP Code:
public function testeveiculos()
 
    $crud 
= new grocery_CRUD();
    
$crud->set_table('veiculos');
    
$crud->columns('marca','modelo','cor','placa');
    
$crud->display_as('marca','modelo');
    
$crud->field_type('id_user','invisible');
    
$crud->set_subject('NOVO VEICULO');
    
$crud->callback_before_insert(array($this,'_current_user'));
    
$crud->callback_before_update(array($this,'_current_user'));
    
$output $crud->render();
    
$this->_example_output($output);
}

        
public function 
_current_user($post_array,$primary_key) {
    
$user $this->ion_auth->user()->row();
    
$post_array['id_user'] = $user->id;
    return 
$post_array;

Reply
#5

(06-19-2018, 08:01 AM)jreklund Wrote: You want veiculos to insert the current logged in user id?

https://www.grocerycrud.com/documentatio...ore_insert
https://www.grocerycrud.com/documentatio...ore_update
https://www.grocerycrud.com/documentatio...ible-field

PHP Code:
public function testeveiculos()
 
    $crud 
= new grocery_CRUD();
    
$crud->set_table('veiculos');
    
$crud->columns('marca','modelo','cor','placa');
    
$crud->display_as('marca','modelo');
    
$crud->field_type('id_user','invisible');
    
$crud->set_subject('NOVO VEICULO');
    
$crud->callback_before_insert(array($this,'_current_user'));
    
$crud->callback_before_update(array($this,'_current_user'));
    
$output $crud->render();
    
$this->_example_output($output);
}

        
public function 
_current_user($post_array,$primary_key) {
    
$user $this->ion_auth->user()->row();
    
$post_array['id_user'] = $user->id;
    return 
$post_array;

   Tanks!!!!! SOLVED!

   thank you so much!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB