⚠ 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

how to condition the display of a link using add_action



bvarlb

bvarlb
  • profile picture
  • Member

Posted 11 April 2013 - 07:12 AM

Hi all,

 

I want to display an icon with a link only on rows having a satisfied condition.

With the code below, each row has the icon with a good link when condition is satisfied or partial link if not

good link : http://localhost/grocerycrud/index.php/main/detail_circuit?id_circuit=1

partial link : http://localhost/grocerycrud/index.php/main/circuits

 

  $crud->add_action('Profil', '', '','profil-icon',array($this,'_profil_callback'));

  function _profil_callback($value, $row)
  {
      if ($row->lien=='')
      {
        return '';
      }
      else
      {
        return site_url('main/detail_circuit').'?id_circuit='.$row->id_circuit;
      }
  }
 

Thanks in advance for your help


davidoster

davidoster
  • profile picture
  • Member

Posted 11 April 2013 - 22:06 PM

If I understand correctly, you need to display an icon.

This can be done by passing either on the $image_url or on the $css_class some value,


- image_url

$crud->add_action('Smileys', 'http://www.grocerycrud.com/assets/uploads/general/smiley.png', 'demo/action_smiley');

 

- css_class

$crud->add_action('Photos', '', '','ui-icon-image',array($this,'just_a_test'));

and on your theme's css have a css definition something like this,

.ui-icon-image {      background-image:url(assets/images/an_image.png);}

 

 

Check here for the full documentation.


davidoster

davidoster
  • profile picture
  • Member

Posted 11 April 2013 - 22:12 PM

Oh I am sorry!

Now I understand.

I believe you need to use jQuery for this because this happens after the display has being rendered. So you need to read the url using jQuery and replace the icons dynamically for those rows that are needed.


bvarlb

bvarlb
  • profile picture
  • Member

Posted 12 April 2013 - 07:03 AM

Thanks for your answer, but finally I've used a solution given here where I use the function callback_column, and inside I can test the condition to display or not the icon with link :

$crud->callback_column('profil',array($this,'_profil_callback'));

 

  function _profil_callback($value, $row)
  {
      if ($row->lien=='')
      {
        return '';
      }
      else
      {
        return '<a href="main/profil_circuit/'.$row->id_circuit.'">'.'<img src="'.base_url().'assets/grocery_crud/themes/perso/css/images/profil.jpg" alt="Profil" title="Profil">'.'</a>';
      }
  }