Jump to content


Dynamic callback_field

callback_field callback field grocerycrud 1.5.x

  • Please log in to reply
No replies to this topic

#1 Gonzalo Morel

Gonzalo Morel

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 20 July 2016 - 09: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; }

 

 

 







Also tagged with one or more of these keywords: callback_field, callback, field, grocerycrud, 1.5.x

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users