cakephp - Display Image next to HABTM checkboxes -


cane give me ideas on please!

i generate multiple checkboxes table related table habtm relationship association. generate multiple checkboxes image along text in label.

my 2 tables items , items_characteristics. item hasandbelongtomany characteristics, , itemcharacteristic hasandbelongtomany items.

echo $this->form->input('item.itemcharacteristic',array(     'label' =>false,     'type'=>'select',     'multiple'=>'checkbox',     'options' => $itemcharacteristics ,     'selected' => $this->html->value('itemcharacteristic.itemcharacteristic') )); 

this code generate list of checkboxes , works perfect: have: enter image description here

which generated db table items_characteristics.

and wanna have:

enter image description here

does have idea how can achieve please?

i assume in controller did like:

$this->request->data = $this->item->find('first',  ... );  

so $data contains information selected characteristics in form of subarray,

edit: assume item habtm itemcharacteristic

then in view

$checked_characteristics = hash::extract($this->data, 'itemcharacteristic.{n}.id'); foreach($itemcharacteristics  $id => $itemcharacteristic ) {     $checked = in_array($id, $checked_characteristics );     $img = $this->html->image('cake.icon.png'); // put here name                                                  // of icon want show                                                 // based on charateristic                                                  // displayng     echo $this->form->input(         'itemcharacteristic.itemcharacteristic.',          array(             'between' => $img,              'label' => $itemcharacteristic,              'value' => $id,               'type' => 'checkbox',             'checked' => $checked         )     ); } 

edit: comment understand $itemcharacteristics come find('list') statement.

change find('all', array('recursive' => -1));

now code becomes

foreach($itemcharacteristics  $itemcharacteristic ) {     $id = $itemcharacteristic['itemcharacteristic']['id'];     $icon_name = $itemcharacteristic['itemcharacteristic']['icon_name']; //or wherever icon path     $img = $this->html->image($icon_name);      $itemcharacteristicname = $itemcharacteristic['itemcharacteristic']['name'];     // same above } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -