當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::singularize方法代碼示例

本文整理匯總了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)));
     }
 }
開發者ID:buildwithcraft,項目名稱:craft-utensils,代碼行數:10,代碼來源:InflectorTest.php

示例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;
 }
開發者ID:cvo-technologies,項目名稱:croogo-webshop-plugin,代碼行數:32,代碼來源:WebshopHelper.php

示例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);
     }
 }
開發者ID:redcapeman,項目名稱:kinspire,代碼行數:30,代碼來源:app_controller.php

示例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');
         }
     }
 }
開發者ID:nani8124,項目名稱:infinitas,代碼行數:26,代碼來源:LibsEvents.php

示例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;
 }
開發者ID:jimeh,項目名稱:zynapse,代碼行數:28,代碼來源:model_generator.php

示例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);
         }
     }
 }
開發者ID:veritech,項目名稱:cakephp-rest-plugin,代碼行數:29,代碼來源:xml.php

示例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));
 }
開發者ID:praveensingh25000,項目名稱:Bivid,代碼行數:35,代碼來源:SiteTypesController.php

示例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');
 }
開發者ID:phpontrax,項目名稱:trax,代碼行數:10,代碼來源:InflectorTest.php

示例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());
 }
開發者ID:jgprolluxer,項目名稱:prosales,代碼行數:30,代碼來源:AppController.php

示例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'));
     }
 }
開發者ID:maverick2041,項目名稱:wpkgexpress,代碼行數:30,代碼來源:variables_controller.php

示例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]);
 }
開發者ID:xXLXx,項目名稱:ddc,代碼行數:25,代碼來源:v1.php

示例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;
 }
開發者ID:rdallasgray,項目名稱:bbx,代碼行數:30,代碼來源:HasMany.php

示例13: _importTables

 function _importTables($from)
 {
     $defaultDb = ConnectionManager::getDataSource($from);
     foreach ($defaultDb->listSources() as $table) {
         $this->fixtures[] = "app." . Inflector::singularize($table);
     }
 }
開發者ID:hiromi2424,項目名稱:ninja,代碼行數:7,代碼來源:fixture_loader_test_case.php

示例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;
 }
開發者ID:jimeh,項目名稱:zynapse,代碼行數:33,代碼來源:layout_generator.php

示例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);
 }
開發者ID:ayaou,項目名稱:Zuha,代碼行數:34,代碼來源:Privilege.php


注:本文中的Inflector::singularize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。