https://docs.joomla.org/Checkboxes_form_field_type
在使用這個欄位類型時,對應的Mysql 可以使用 char(12) 類型
然後需要修改在後台元件的以下檔案
administrator\components\com_name\tables\com_name.php
必須 Overloaded bind 這個 function, 如已經有Overloaded 此 function 了則直接加上對應欄位的語法
這邊假設欄位名稱為 checkboxes_test
則需要在bind 這個 function 中加入以下語法
if (!empty($array['checkboxes_test']))
{
if (is_array($array['checkboxes_test']))
{
$array['checkboxes_test'] = implode(',', $array['checkboxes_test']);
}
elseif (strpos($array['checkboxes_test'], ',') != false)
{
$array['checkboxes_test'] = explode(',', $array['checkboxes_test']);
}
}
else
{
$array['checkboxes_test'] = '';
}
如果你是還沒有 overloaded bind function 的話,則在元件table類別加上以下function
public function bind($array, $ignore = '')
{
if (!empty($array['checkboxes_test']))
{
if (is_array($array['checkboxes_test']))
{
$array['checkboxes_test'] = implode(',', $array['checkboxes_test']);
}
elseif (strpos($array['checkboxes_test'], ',') != false)
{
$array['checkboxes_test'] = explode(',', $array['checkboxes_test']);
}
}
else
{
$array['checkboxes_test'] = '';
}
return parent::bind($array, $ignore);
}
...