Hi,
I’m using the settings (http://www.yiiframework.com/extension/settings/) extension to manage the app settings that should be configurable by admin. I’m using tabular input method to get/set settings in a bulk manner. Since I’m collecting the setting inputs from user & using the tabular input, I’m not able to use the settings extension’s native get/set method because it serializes and unserializes when setting & retrieving.
Here’s my settings controller code:
$settings = Setting::model()->findAll();
if(isset($_POST['Setting']))
{
$valid = true;
foreach($settings as $i => $setting)
{
if(isset($_POST['Setting'][$i]))
$setting->attributes = $_POST['Setting'][$i];
$valid = $setting->validate() && $valid;
}
if($valid)
{
foreach($settings as $i => $setting)
{
if(isset($_POST['Setting'][$i]))
$setting->attributes = $_POST['Setting'][$i];
$setting->save();
}
}
}
<!-- Settings form -->
<?php foreach($settings as $i => $setting):?>
<?php echo $form->errorSummary($setting); ?>
<div class="row">
<?php echo $form->labelEx($setting,"[$i]category"); ?>
<?php echo $form->labelEx($setting,"[$i]key"); ?>
</div>
<div class="row">
<?php echo $form->labelEx($setting,"[$i]value"); ?>
<?php echo $form->textField($setting,"[$i]value"); ?>
<?php echo $form->error($setting,"[$i]value"); ?>
</div>
<?php endforeach;?>
<?php echo CHtml::submitButton('Submit'); ?>
<?php $this->endWidget(); ?>
I also have a setting model associated with it. To automatically serialize/unserialize I think I need to have a behavior that mimics the extensions logic to automatically does this conversion, but not sure. Can anyone help on this regard? Or how do you create an interface for this setting?