Skip to content

Instantly share code, notes, and snippets.

@cgmartin
Last active August 29, 2015 14:17
Show Gist options
  • Save cgmartin/02a939557c9517a8830e to your computer and use it in GitHub Desktop.
Save cgmartin/02a939557c9517a8830e to your computer and use it in GitHub Desktop.
<?php
//
// Config Groupings
//
$configGroups = array(
'group1' => array('label' => 'Simple Options', 'sort' => 1),
'group2' => array('label' => 'Complex Options', 'sort' => 2),
'group3' => array('label' => 'Multi Options', 'sort' => 3),
);
//
// Config Options
//
$configOptions = array(
'group1' => array(
//
// Simple Options
//
// Key will be automatically converted to a label
//
'useCamelCase' => true,
'or-dashes' => false,
'or_underscores' => true,
'simpleText' => 'Some text',
'simpleNumber' => '50',
'simpleSelect' => array('Foo', 'Bar', 'Dev', 'Null'),
),
'group2' => array(
//
// Complex Options examples
//
'boolOption' => array(
'input_type' => 'radio',
'label' => 'Boolean Option',
'value_options' => array('1' => 'True', '' => 'False'),
'default_value' => false,
),
'textOption' => array(
'input_type' => 'text',
'label' => 'Text Option',
'default_value' => 'My Site',
),
'numberOption' => array(
'input_type' => 'number',
'label' => 'Number Option',
'default_value' => '10',
),
),
'group3' => array(
//
// Complex Multi-Options examples
//
'multiCheckboxOption' => array(
'input_type' => 'multicheckbox',
'label' => 'MultiCheckbox Option',
'value_options' => array('foo' => 'Foo Label', 'bar' => 'Bar label', 'dev' => 'Dev label', 'null' => 'Null Label'),
'default_value' => array('foo', 'dev'),
),
'radioOption' => array(
'label' => 'Radio Option',
'input_type' => 'radio',
'value_options' => function ($configOption) {
// Callbacks can be used to feed options
return array('Foo', 'Bar', 'Dev', 'Null');
},
'default_value' => 'Bar',
),
'selectOption' => array(
'label' => 'Select Option',
'input_type' => 'select',
'value_options' => array('Spring', 'Summer', 'Fall', 'Winter'),
'default_value' => 'Fall',
),
),
);
$settings = array(
'zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
'config_values_table' => 'configadminvalues',
'config_options' => array(
'site' => $configOptions,
),
'config_groups' => array(
'site' => $configGroups,
),
);
return array(
'cgmconfigadmin' => $settings,
'service_manager' => array(
'aliases' => array(
'cgmconfigadmin_zend_db_adapter' => (isset($settings['zend_db_adapter'])) ? $settings['zend_db_adapter']: 'Zend\Db\Adapter\Adapter',
),
),
// Route configuration
'router' => array(
'routes' => array(
'cgmconfigadmin' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/config-admin',
'defaults' => array(
'controller' => 'CgmConfigAdmin_ConfigOptionsController',
'action' => 'index',
),
),
'may_terminate' => true,
),
),
),
// ZfcAdmin integration example
/*
'router' => array(
'routes' => array(
'zfcadmin' => array(
'child_routes' => array(
'cgmconfigadmin' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/config',
'defaults' => array(
'controller' => 'CgmConfigAdmin_ConfigOptionsController',
'action' => 'index',
),
),
),
),
),
),
),
'navigation' => array(
'admin' => array(
'cgmconfigadmin' => array(
'label' => 'Config',
'route' => 'zfcadmin/cgmconfigadmin',
),
),
),
*/
);
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$sm = $this->getServiceLocator();
$settingValue = $sm->get('cgmconfigadmin')->getConfigValue('group3/multiCheckboxOption');
\Zend\Debug\Debug::dump($settingValue);
return new ViewModel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment