⚠ 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

Dynamic callback_field



Gonzalo Morel
  • profile picture
  • Member

Posted 20 July 2016 - 21:56 PM

just i share this solutión to create dynamic callback_field, i used just callback_field but i think works to other callbacks
 
 
with this solution, you can use the same function to all field you want

 

 
pd: sorry for my english
function somefunction(){
$crud = new Grocery_CRUD();
$crud->set_table('some_table');
/*...*/

$crud->callback_field('some_field', array($this,'callback_selectImage'));//normal call
$crud->callback_field('some_other_field', array($this,'callback_selectImage')); //normal call

/*...*/ $this->salida($output); }


/**
     * $callback = 
     * stdClass Object
      * (
      *     [name] => some_field
      *     [type] => int
      *     [max_length] => 11
      *     [default] => 7
      *     [primary_key] => 0
      *     [db_max_length] => 11
      *     [db_type] => int
      *     [db_null] => 
      *     [db_extra] => 
      *     [required] => 
      *     [display_as] => Imagen de fondo del contenedor
      *     [crud_type] => relation
      *     [extras] => Array
      *         (
      *             [0] => qb_contain_bg_image_id
      *             [1] => gm_imgs
      *             [2] => image_name
      *             [3] => 
      *             [4] => 
      *         )
      *
      * )
     * 
     * 
     * @param type $value
     * @param type $primary_key
     * @param type $callback
     * @return string
     */

 

public function callback_selectImage($value="", $primary_key = null, $callback) { $img = new Images_model(); //object to table images $res = $img->get_all_img_buttons(); //get all images $out = '<select class="form-control select2 sel_image" id="field-'.$callback->name.'" name="'.$callback->name.'" placeholder="Seleccionar Tipo" >'; $out .= '<option value="" selected disabled>Seleccionar</option>'; foreach($res as $key=>$val): if($value == $val->image_id): $out .= '<option value="'.$val->image_id.'" title="'.base_url().'assets/uploads/imgs/'.$val->image_url.'" selected>'.$val->image_name.'</option>'; else: $out .= '<option value="'.$val->image_id.'" title="'.base_url().'assets/uploads/imgs/'.$val->image_url.'">'.$val->image_name.'</option>'; endif; endforeach; $out .= '</select>'; return $out; }