/** * Set default names for views and models * * @param array An optional associative array of configuration settings. * @return void */ protected function _setDefaultNames($config = array()) { $prefix = strtolower($this->getName()); $suffix = strtolower($this->getNameSuffix()); // Default view name if (array_key_exists('default_view', $config)) { $this->_defaultView = $config['default_view']; } else { if (empty($suffix)) { // use the prefix $this->_defaultView = $prefix; } else { // Use suffix if it's plural, otherwise plurizalize it if (EInflector::isSingular($suffix)) { $this->_defaultView = EInflector::pluralize($suffix); } else { $this->_defaultView = $suffix; } } } // Default model name if (array_key_exists('default_model', $config)) { $this->_defaultModel = $config['default_model']; } else { // Default model names are always singular $this->_defaultModel = empty($suffix) ? $prefix : $suffix; } }
/** * Set default names for views and models * * @param array An optional associative array of configuration settings. * @return void */ protected function _setDefaultNames($config = array()) { parent::_setDefaultNames($config); $prefix = strtolower($this->getName()); $suffix = strtolower($this->getNameSuffix()); // Grid view name if (array_key_exists('list_view', $config)) { $this->_listView = $config['list_view']; } else { if (EInflector::isSingular($this->_defaultView)) { $this->_listView = EInflector::pluralize($this->_defaultView); } else { $this->_listView = $this->_defaultView; } } // Edit view name if (array_key_exists('item_view', $config)) { $this->_itemView = $config['item_view']; } else { $singularView = EInflector::singularize($this->_listView); if (!empty($singularView)) { $this->_itemView = $singularView; } else { if (!empty($suffix)) { $this->_itemView = $suffix; } else { $this->_itemView = $prefix; } } } }
public function testIsPlural() { $this->assertTrue(EInflector::isSingular('test')); $this->assertTrue(EInflector::isPlural('tests')); }