Initial commit of Config Controller and View.

* Allows basic updating of config options
 * No validation yet
 * All options are rendered as text boxes.  Some need to be dropdown, etc.
This commit is contained in:
Kyle Johnson 2013-05-06 11:06:58 -04:00
parent 869b84732d
commit f35e7cbe73
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php
class ConfigController extends AppController {
public function index() {
$configs['fields'] = array('Name', 'Id', 'Value', 'Prompt', 'Type');
$configs['order'] = array('Config.Category ASC');
$this->set('configs', $this->Config->find('all', $configs));
if (!empty($this->request->data)) {
$data = array();
foreach ($this->request->data['Config'] as $key => $value) {
foreach ($value as $fieldName => $fieldValue) {
$arr = array('Config' => array('Name' => $fieldName, 'Value' => $fieldValue));
array_push($data, $arr);
}
}
if($this->Config->saveMany($data)) {
$this->Session->setFlash('Your config has been updated.');
} else {
$this->Session->setFlash('Your config has not been updated.');
}
}
}
}
?>

View File

@ -0,0 +1,20 @@
<h2>Configs</h2>
<?php
echo $this->Form->create('Config', array(
'url' => '/config',
'novalidate' => true
));
foreach ($configs as $config):
$id = $config['Config']['Id'];
$inputname = 'Config.' . $id . '.' . $config['Config']['Name'];
echo $this->Form->input($inputname, array(
'default' => $config['Config']['Value'],
'label' => $config['Config']['Name'],
'after' => $config['Config']['Prompt'],
));
endforeach;
unset($config);
echo $this->Form->end('Save Config');
?>
</table>