⚠ 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

callback_add_field problem



maha
  • profile picture
  • Member

Posted 09 February 2013 - 14:07 PM

my code is

 function management($artid)
    {
        $crud = new grocery_CRUD();
        $crud->set_subject(lang('more_photos'));
        $crud->set_table('art_pic');
        $crud->set_relation('art_id','article','Name');
$crud->fields('art_id','name','img_url');	
$crud->callback_add_field('art_id',array($this,'add_field_callback_1'));
$output = $crud->render();
                $this->_output_data($output);
    }
function add_field_callback_1($artid)
    {
      //echo $artid;
       $query= $this->admin_model->Article_name($artid); 
     //  var_dump($query);
       $name="";
       foreach ($query as $value)
       {
           $name=$value->Name; 
       }
     return $name;
    }

but it doesn't return any thing.


Nexima
  • profile picture
  • Member

Posted 09 February 2013 - 14:26 PM

are you sure from query?

 

$this->output->enable_profiler(TRUE);

 

check from bottom of the page


victor
  • profile picture
  • Member

Posted 09 February 2013 - 17:17 PM

callback_add_field function hasn't arguments!
have a look at documentation. http://www.grocerycrud.com/documentation/options_functions/callback_add_field.
It only returns html code.
But you can use session.
What do you want to make?
you create a new record  and you haven't id before inserting.


maha
  • profile picture
  • Member

Posted 11 February 2013 - 09:51 AM

what i'm want is:

insert new photo with the pased $artid

and the name of article shown in the add field form

 this is the code after update

       $crud = new grocery_CRUD();
        $crud->set_subject(lang('more_photos'));
        $crud->set_table('art_pic');
        $crud->set_relation('art_id','article','Name');
       
        $crud->where("art_id = $artid");
        $crud->columns('art_id','name','img_url');
        $crud->display_as('art_id',lang('art_id'))
                ->display_as('name',lang('photo_name'))
                ->display_as('img_url',lang('img_url'));
        
        $crud->set_language(lang('lang'));
        $crud->fields('art_id','name','img_url');	   
        $crud->change_field_type('art_id','hidden',$artid); 
       
        $crud->set_field_upload('img_url', 'assets/uploads/');
        //---------->>>>call back functions 
        $crud->callback_add_field('art_id',array($this,'add_field_callback_1'));
       $crud->callback_edit_field('art_id',array($this,'edit_field_callback_1'));
       
       $output = $crud->render();
        $this->_output_data($output);
    }
function add_field_callback_1()
    {
      
       $query= $this->admin_model->Article_name($this->uri->segment(4)); 
      return $query['Name'];
     }

it shown the article name but photo stored in data base with art_id=0

when i stopped the call back the photo inserted correctly but the name of article doesn't appeared  in add form

please help?


maha
  • profile picture
  • Member

Posted 11 February 2013 - 12:56 PM

hello any help???


victor
  • profile picture
  • Member

Posted 11 February 2013 - 14:43 PM

you can't use these functions together
$crud->change_field_type('art_id','hidden',$artid);
$crud->callback_add_field('art_id',array($this,'add_field_callback_1'));

davidoster
  • profile picture
  • Member

Posted 11 February 2013 - 17:28 PM

The way you do it is wrong!

I don't have time to explain to you know.

Basically you need to use this: http://www.grocerycrud.com/documentation/options_functions/callback_before_insert or this http://www.grocerycrud.com/documentation/options_functions/callback_before_update


maha
  • profile picture
  • Member

Posted 12 February 2013 - 07:12 AM

i use the callback_before_insert  but it doesn't work

the article name didn't appeared.


davidoster
  • profile picture
  • Member

Posted 12 February 2013 - 11:20 AM

Then you need to share you code(zip file) and database(sql file) in order to check it out.

Send them to me if you want via a private message.


Shaniba Shanif
  • profile picture
  • Member

Posted 04 September 2017 - 10:09 AM

I have the same Issue . Please Help. Am new to grocery crud.

 

$crud->set_table('product');
            $crud->set_subject('Products');
            $crud->columns('product_name','product_shortdesc','product_image');
            $crud->fields('product_name','product_shortdesc','product_specs','product_image');
            $crud->callback_add_field('categories',array($this,'product_categories_add_callback'));
            $crud->display_as('product_name','Product Name');
            $crud->display_as('product_shortdesc','Product Shortdesc');
            $crud->display_as('product_image','Image');

 

 

Actual requirement i want is 'categories' is a dropdown which is storing in another table whith product id while insertion.


Amit Shah
  • profile picture
  • Member

Posted 04 September 2017 - 12:37 PM

Well - u can refer to the following URL

 

https://www.grocerycrud.com/documentation/options_functions/field_type

This will be a better option to use - field_type instead of the callback - add / edif. If u use Add - u have to enable /manage the same for Edit. Instead, for a case like yours - i will recommend you use field_type 

populate it with dropdown ... Since the value is going to be the same in the drop down what u set while adding, it will automatically pick the same up.

 

Happy GCing :)