⚠ 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

overwrite set_relation display column



mephi
  • profile picture
  • Member

Posted 24 January 2013 - 08:58 AM

Hello guys,

I have a table with a column that store a FK from another table.

I use set_relation to display on each row instead of the id, some other info's related from the fk table.
I also want to make that field a link, to send the user to an url when clicked and I want to achieve this by using callback_column function. However, it seems that set_relation function is overwriting the callback_column function.
Here is my code:

$crud->columns('id_excursion','date_group','date_pickup','max_pax','id_creator');
$crud->set_relation('id_creator','persons','{lname} {fname} <br/>{email}');
$crud->callback_column('id_creator', array($this,'linkContact'));

my callback function

function linkContact($value, $row){
return "<a href='".base_url('admin/admin/contactPerson/'.$row->id_creator)."'>$value</a>";
}


I also want to mention that if I try to add the link to the other controller/action in the set_relation third param like:

$crud->set_relation('id_creator','persons','<a href="'.base_url('admin/admin/contactPerson/'.'{id}'.).'">{lname} {fname} <br/>{email}</a>');

The tags/links get stripped in a nasty way and links never get displayed...

Looking forward for a reply!

victor
  • profile picture
  • Member

Posted 24 January 2013 - 09:09 AM

Yes, there is this problem.
/topic/1087-updated-24112012-dependent-dropdown-library/page__st__100#entry4959

mephi
  • profile picture
  • Member

Posted 24 January 2013 - 09:31 AM

Hello Victor,
I've read the post from there, and David is linking to another post but I haven't understand what he refers to...
/topic/1087-updated-24112012-dependent-dropdown-library/page__st__100#entry4971

Is there a solution for this problem after all or ... ?

mephi
  • profile picture
  • Member

Posted 24 January 2013 - 09:33 AM

Let's say I want to quit creating a link from that column and I want to add an action separately.
By default at the end of the action url I get the id of the current table as parameter. I want to have instead the id_creator value. How I could achieve this?

Edit:
Please ignore this last question ... I can add a callback to the action ... read it on add_action documentation.

However, is there a solution for the initial problem I posted?

victor
  • profile picture
  • Member

Posted 24 January 2013 - 09:37 AM

You can use a callback function

function just_a_test($primary_key , $row)
{
return site_url('demo/action/action_photos').'?country='.$row->country;
}


you can use $primary or $row as you like.
All cases is here http://www.grocerycr...ions/add_action

victor
  • profile picture
  • Member

Posted 24 January 2013 - 09:54 AM

I don't know because I haven't this problem yet

davidoster
  • profile picture
  • Member

Posted 27 January 2013 - 17:18 PM

[quote name='mephi' timestamp='1359019875' post='5257']
Hello Victor,
I've read the post from there, and David is linking to another post but I haven't understand what he refers to...
http://www.grocerycr...__100#entry4971

Is there a solution for this problem after all or ... ?
[/quote]

Within your controller put this function:

function unique_field_name($field_name) {
return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not with a number
}


and then at the callback column have this:

$crud->callback_column($this->unique_field_name('id_creator'), array($this,'linkContact'));


This will make the set_relation and callback_column work happily together!!!

UPD: use this set_relation [color=#000000][size=2]$crud[/size][/color][color=#666600][size=2]->[/size][/color][color=#000000][size=2]set_relation[/size][/color][color=#666600][size=2]([/size][/color][color=#008800][size=2]'id_creator'[/size][/color][color=#666600][size=2],[/size][/color][color=#008800][size=2]'persons'[/size][/color][color=#666600][size=2],[/size][/color][color=#008800][size=2]'{lname} {fname} <br/>{email}'[/size][/color][color=#666600][size=2]);[/size][/color]