/** * @description initialize self config (if it exists) * @return void * @author Se# * @version 0.0.1 */ public function init() { $path = APPLICATION_PATH . '/configs/Controllers/' . $this->_getParam('controller') . '.json'; $action = $this->_getParam('action'); if (file_exists($path)) { $this->selfConfig = json_decode(file_get_contents($path), true); // Append CSS if it needs if (isset($this->selfConfig[$action]['css'])) { foreach ($this->selfConfig[$action]['css'] as $css) { $this->view->headLink()->appendStylesheet($this->view->baseUrl() . $css); } } // Append JS if it needs if (isset($this->selfConfig[$action]['js'])) { foreach ($this->selfConfig[$action]['js'] as $js) { $this->view->headScript()->appendFile($this->view->baseUrl() . $js); } } } else { Evil_Action_Abstract::autoLoad($this); } }
/** * @description create options for form by table scheme * @param object $table * @return array * @author Se# * @version 0.0.2 */ protected function _createFormOptionsByTable($ignorePersonalConfig = false) { $table = self::_('table'); $action = self::getStatic('params', 'action'); $config = self::_('config'); if (!$ignorePersonalConfig) { $controllerConfig = isset(self::_('controller')->selfConfig[$action]['form']) ? self::_('controller')->selfConfig[$action]['form'] : array('elements' => array()); $actionConfig = isset($config->{$action}) ? $config->{$action}->toArray() : array(); } else { $controllerConfig = array(); $actionConfig = array(); } $metadata = $table->info('metadata'); // get metadata self::$metadata = $metadata; // save for different aims $options = array('method' => 'post', 'elements' => array()); // basic options $options = array_merge_recursive($options, $controllerConfig); foreach ($metadata as $columnName => $columnScheme) { if ($columnScheme['PRIMARY']) { // don't show if primary key continue; } $typeOptions = Evil_Form::getFieldType($columnScheme['DATA_TYPE']); // return array('type'[, 'options']) $attrOptions = array('label' => ucfirst($columnName)); if (isset($actionConfig['default'])) { $attrOptions += $actionConfig['default']; } $options = Evil_Form::setFormField($options, $columnName, $attrOptions, $typeOptions); } $options['elements']['do'] = array('type' => 'hidden', 'options' => array('value' => $action)); // add submit button $options['elements']['submit'] = array('type' => 'submit'); // add submit button return $options; }