本文整理匯總了PHP中Inflector::singularize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::singularize方法的具體用法?PHP Inflector::singularize怎麽用?PHP Inflector::singularize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::singularize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_singularize_plurals
public function test_singularize_plurals()
{
$ar = (require __DIR__ . '/cases/singular_to_plural.php');
foreach ($ar as $singular => $plural) {
$this->assertEquals($singular, self::$inflector->singularize($plural));
$this->assertEquals($singular, self::$inflector->singularize($singular));
$this->assertEquals(ucfirst($singular), self::$inflector->singularize(ucfirst($plural)));
$this->assertEquals(ucfirst($singular), self::$inflector->singularize(ucfirst($singular)));
}
}
示例2: panelTabs
/**
* Show tabs
*
* @return string
*/
public function panelTabs($show = null)
{
if (!isset($this->adminTabs)) {
$this->adminTabs = false;
}
$output = '';
$tabs = Configure::read('Webshop.panel.tabs.' . Inflector::camelize($this->request->params['controller']) . '/' . $this->request->params['action']);
if (is_array($tabs)) {
foreach ($tabs as $title => $tab) {
$tab = Hash::merge(array('options' => array('linkOptions' => array(), 'elementData' => array(), 'elementOptions' => array())), $tab);
if (!isset($tab['options']['type']) || isset($tab['options']['type']) && in_array($this->_View->viewVars['typeAlias'], $tab['options']['type'])) {
$domId = strtolower(Inflector::singularize($this->request->params['controller'])) . '-' . strtolower(Inflector::slug($title, '-'));
if ($this->adminTabs) {
list($plugin, $element) = pluginSplit($tab['element']);
$elementOptions = Hash::merge(array('plugin' => $plugin), $tab['options']['elementOptions']);
$output .= '<div id="' . $domId . '" class="tab-pane">';
$output .= $this->_View->element($element, $tab['options']['elementData'], $elementOptions);
$output .= '</div>';
} else {
$output .= $this->panelTab(__d('croogo', $title), '#' . $domId, $tab['options']['linkOptions']);
}
}
}
}
$this->adminTabs = true;
return $output;
}
示例3: flash
function flash($message, $url)
{
$controllerName = Inflector::humanize(Inflector::singularize($this->params['controller']));
if ($url == 'dashboard') {
$url = array('controller' => 'projects', 'action' => 'index');
} elseif ($url == 'index') {
$url = array('action' => 'index');
}
switch ($message) {
case 'saved':
$message = 'The ' . $controllerName . ' has been saved.';
break;
case 'deleted':
$message = 'The ' . $controllerName . ' has been deleted.';
break;
case 'failed':
$message = 'The ' . $controllerName . ' could not be saved. Please try again';
break;
case 'invalid':
$message = 'Invalid ' . $controllerName . '.';
break;
case 'noid':
$message = 'Invalid ID.';
break;
}
$this->Session->setFlash($message);
if (!empty($url)) {
$this->redirect($url);
}
}
示例4: onAttachBehaviors
public function onAttachBehaviors($event)
{
if ($event->Handler->shouldAutoAttachBehavior()) {
// attach the expandable (eva) behavior if there is a table for it
$attributesTable = Inflector::singularize($event->Handler->tablePrefix . $event->Handler->table) . '_attributes';
if (in_array($attributesTable, $event->Handler->getTables($event->Handler->useDbConfig))) {
$event->Handler->bindModel(array('hasMany' => array($event->Handler->name . 'Attribute' => array('className' => Inflector::camelize($attributesTable), 'foreignKey' => Inflector::underscore($event->Handler->name) . '_id', 'dependent' => true))), false);
$event->Handler->Behaviors->attach('Libs.Expandable');
}
if ($event->Handler->shouldAutoAttachBehavior('Libs.Sluggable', array('slug'))) {
$event->Handler->Behaviors->attach('Libs.Sluggable', array('label' => array($event->Handler->displayField)));
}
if ($event->Handler->shouldAutoAttachBehavior('Libs.Sequence', array('ordering'))) {
$event->Handler->Behaviors->attach('Libs.Sequence');
}
if ($event->Handler->shouldAutoAttachBehavior('Libs.Rateable', array('rating'))) {
$event->Handler->Behaviors->attach('Libs.Rateable');
}
if ($event->Handler->shouldAutoAttachBehavior('Tree', array('lft', 'rght')) && $event->Handler->shouldAutoAttachBehavior('InfiniTree', array('lft', 'rght'))) {
$event->Handler->Behaviors->attach('Tree');
}
if ($event->Handler->shouldAutoAttachBehavior('Libs.Validation')) {
$event->Handler->Behaviors->attach('Libs.Validation');
}
}
}
示例5: generate
function generate()
{
$this->name = Inflector::singularize($this->name);
$this->class_name = Inflector::camelize($this->name);
$model_template = $this->templates_path . '/model.php';
if (stristr($this->name, '_')) {
$model_file = Znap::$models_path . '/' . strtolower($this->name) . '.php';
} else {
$model_file = Znap::$models_path . '/' . Inflector::underscore($this->name) . '.php';
}
if (!is_file($model_file)) {
if (is_file($model_template)) {
$model_data = file_get_contents($model_template);
$model_data = str_replace('[class_name]', $this->class_name, $model_data);
if (file_put_contents($model_file, $model_data)) {
$this->echo_create($model_file);
} else {
$this->echo_create_error($model_file, 'model');
}
} else {
$this->echo_template_error($model_template, 'model');
exit;
}
} else {
$this->echo_exists($model_file);
}
return true;
}
示例6: arr2Xml
function arr2Xml($arr)
{
foreach ($arr as $key => $val) {
//starting tag
if (!is_numeric($key)) {
$this->response .= sprintf('<%s>', $key);
}
//Another array
if (is_array($val)) {
//Handle non-associative arrays
if ($this->is_numerically_indexed_array($val)) {
foreach ($val as $item) {
$tag = Inflector::singularize($key);
$this->response .= sprintf("<%s>", $tag);
$this->arr2Xml($item);
$this->response .= sprintf("</%s>", $tag);
}
} else {
$this->arr2Xml($val);
}
} elseif (is_string($val)) {
$this->response .= $val;
}
//Draw closing tag
if (!is_numeric($key)) {
$this->response .= sprintf('</%s>', $key);
}
}
}
示例7: admin_index
function admin_index()
{
/* Active/Inactive/Delete functionality */
if (isset($this->request->data["SiteType"]["setStatus"])) {
//pr($this->request->data);die;
if (!empty($this->request->data['SiteType']['status'])) {
$status = $this->request->data['SiteType']['status'];
} else {
$this->Session->setFlash("Please select the action.", 'default', array('class' => 'alert alert-danger'));
$this->redirect(array('action' => 'admin_index'));
}
$CheckedList = $this->request->data['checkboxes'];
$model = 'SiteType';
$controller = $this->params['controller'];
$action = $this->params['action'];
parent::setStatus($status, $CheckedList, $model, $controller, $action);
}
/* Active/Inactive/Delete functionality */
$value = "";
$value1 = "";
$show = "";
$criteria = "";
if (!empty($this->params)) {
if (!empty($this->params->query['keyword'])) {
$criteria .= " SiteType.name LIKE '%" . trim($this->params->query['keyword']) . "%' ";
}
}
$this->Paginator->settings = array('conditions' => array($criteria), 'limit' => Configure::read('Settings.paginationLimit'), 'order' => array('SiteType.id' => 'DESC'));
$this->set('getData', $this->Paginator->paginate('SiteType'));
$this->set('keyword', $value);
$this->set('show', $show);
$this->set('navadmins', 'class = "active"');
$this->set('breadcrumb', 'SiteTypes/Listing');
$this->set('models', Inflector::singularize($this->name));
}
示例8: testSingularize
/**
* Test {@link Inflector::singularize()}
*/
public function testSingularize()
{
$this->assertEquals(Inflector::singularize('orders'), 'order');
$this->assertEquals(Inflector::singularize('people'), 'person');
$this->assertEquals(Inflector::singularize('processes'), 'process');
$this->assertEquals(Inflector::singularize('queries'), 'query');
}
示例9: beforeRender
public function beforeRender()
{
$this->Navigation->Process($this);
$this->set('trail', $this->Navigation->trail);
$this->loadModel('Config');
$config = $this->Config->find('all', array('conditions' => array('Config.active_flg' => true)));
$config = $config[0];
$this->loadModel('User');
$this->User->recursive = 1;
$signedUser = $this->User->read(null, $this->Session->read('Auth.User.id'));
$slangConf = '';
if (isset($config['Config']['prefLanguage'])) {
$slangConf = $config['Config']['prefLanguage'];
}
Configure::write('Config.language', $slangConf);
$this->appLangConf = $slangConf;
try {
$relObjType = Inflector::singularize($this->name);
} catch (Exception $ex) {
$relObjType = "";
}
$relObjId = isset($this->data[$relObjType]["id"]) ? $this->request->data[$relObjType]["id"] : 0;
$this->set('slangConf', $slangConf);
$this->set('menu', $this->buildMainMenu());
$this->set('config', $config);
$this->set('signedUser', $signedUser);
$this->set('relObjType', $relObjType);
$this->set('relObjId', $relObjId);
$this->set('pricelistID', $this->getPricelistID());
}
示例10: add
function add($type = null, $recordId = null)
{
if (!ctype_digit($recordId) || !ctype_alpha($type) || ($model =& ClassRegistry::init(strtolower($type))) == false) {
$this->_showCritError('Invalid type and/or record id');
} else {
$type = ucwords(Inflector::singularize(strtolower($type)));
if (!empty($this->data)) {
if (($type_id = constant('VARIABLE_TYPE_' . strtoupper($type))) === false) {
$type_id = -1;
}
// Will cause validation to fail, since we only use positive integers
$this->Variable->create();
$this->data['Variable']['ref_id'] = $recordId;
$this->data['Variable']['ref_type'] = $type_id;
if ($this->Variable->save($this->data)) {
$this->Session->setFlash('The Variable has been saved');
$this->redirect(array('action' => 'view', $type, $recordId));
//$this->redirect(array('controller' => Inflector::pluralize(strtolower($type)), 'action'=>'view', $recordId));
} else {
$this->Session->setFlash('The Variable could not be saved');
}
}
$name = $model->field($model->displayField, array("{$type}.id" => $recordId));
if (!$name) {
$this->Session->setFlash("Invalid {$type} id.");
$this->redirect(array('controller' => strtolower($type), 'action' => 'index'));
}
$this->set(compact('type', 'recordId', 'name'));
}
}
示例11: action_update
public function action_update($controller, $id = null)
{
$class = $this->getClass($controller);
$success = false;
$errors = [];
if (!$id) {
$errors[] = 'Please include a PK ID';
return $this->response(['errors' => $errors]);
}
$obj = $class::find($id);
if (!$obj) {
$errors[] = 'Cannot find ' . Inflector::singularize(Inflector::humanize($controller)) . ' with ID: ' . $id;
} else {
foreach (Input::post() as $key => $value) {
$obj->{$key} = $value;
}
$success = $obj->save();
if (!$success) {
$errors[] = 'Could not save ' . Inflector::singularize(Inflector::humanize($controller));
} else {
$data = $obj;
}
}
return $this->response(['data' => $data, 'success' => $success, 'errors' => $errors]);
}
示例12: getExternalConditions
public static function getExternalConditions($select, $parentModel, $childName, $attributes)
{
$parentModelName = get_class($parentModel);
$parentTableName = $parentModel->getTableName();
// exhibitions
$childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName;
$childModelName = Inflector::classify($childName);
$childTableName = Bbx_Model::load($childModelName)->getTableName();
// images
if (!array_key_exists($childTableName, $select->getPart('from'))) {
$select->from($childTableName, array());
// images
}
if (array_key_exists('as', $attributes)) {
$refColumn = $attributes['as'] . '_id';
$polyType = $attributes['as'] . '_type';
} else {
$refColumn = Inflector::singularize($parentTableName) . '_id';
}
try {
$parentModel->getRowData();
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id);
} catch (Exception $e) {
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`");
}
if (isset($polyType)) {
$select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'");
}
return $select;
}
示例13: _importTables
function _importTables($from)
{
$defaultDb = ConnectionManager::getDataSource($from);
foreach ($defaultDb->listSources() as $table) {
$this->fixtures[] = "app." . Inflector::singularize($table);
}
}
示例14: generate
function generate()
{
$layout_template = $this->templates_path . '/layout.phtml';
if (is_file($layout_template)) {
$this->name = Inflector::singularize($this->name);
$this->class_name = Inflector::camelize($this->name);
if (stristr($this->name, '_')) {
$layout_filename = strtolower($this->name) . '.' . Znap::$views_extension;
} else {
$layout_filename = Inflector::underscore($this->name) . '.' . Znap::$views_extension;
}
$view_paths = glob(Znap::$app_path . '/views*');
foreach ($view_paths as $path) {
$layout_file = $path . '/__layouts/' . $layout_filename;
if (!is_file($layout_file)) {
$layout_data = file_get_contents($layout_template);
$layout_data = str_replace('[layout]', $this->name, $layout_data);
if (file_put_contents($layout_file, $layout_data)) {
$this->echo_create($layout_file);
} else {
$this->echo_create_error($layout_file, 'layout');
exit;
}
} else {
$this->echo_exists($layout_file);
}
}
} else {
$this->echo_template_error($layout_template, 'layout');
exit;
}
return true;
}
示例15: _writeLinkPermissions
/**
* Write link permissions method
*
*/
protected function _writeLinkPermissions()
{
$acos = array();
$privileges = $this->find('all', array('conditions' => array('Privilege._create' => 1, 'Privilege._read' => 1, 'Privilege._update' => 1, 'Privilege._delete' => 1)));
foreach ($privileges as $privilege) {
if (!empty($acos[$privilege['Privilege']['aco_id']])) {
$acos[$privilege['Privilege']['aco_id']] = $acos[$privilege['Privilege']['aco_id']] . ',' . $privilege['Privilege']['aro_id'];
} else {
$acos[$privilege['Privilege']['aco_id']] = $privilege['Privilege']['aro_id'];
}
}
$settings = '';
foreach ($acos as $aco => $aros) {
$path = $this->Section->getPath($aco);
// all of the acos parents
if ($path === null) {
// if path is null we need to delete the aros_acos that use that aco because it doesn't exist
$this->deleteAll(array('Privilege.aco_id' => $aco));
} else {
$url = str_replace('controllers', '', Inflector::singularize(Inflector::tableize(ZuhaInflector::flatten(Set::extract('/Section/alias', $path), array('separator' => '/')))));
$settings .= $url . ' = ' . $aros . PHP_EOL;
}
}
App::uses('Setting', 'Model');
$Setting = new Setting();
$data['Setting']['type'] = 'APP';
$data['Setting']['name'] = 'LINK_PERMISSIONS';
$data['Setting']['value'] = trim($settings);
$Setting->add($data);
}