当前位置: 首页>>代码示例>>PHP>>正文


PHP Inflector::variable方法代码示例

本文整理汇总了PHP中Cake\Utility\Inflector::variable方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::variable方法的具体用法?PHP Inflector::variable怎么用?PHP Inflector::variable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Utility\Inflector的用法示例。


在下文中一共展示了Inflector::variable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filterAssociations

 /**
  * Returns filtered associations for controllers models. HasMany association are filtered if
  * already existing in BelongsToMany
  *
  * @param Table $model The model to build associations for.
  * @return array associations
  */
 public function filterAssociations(Table $model)
 {
     $belongsToManyJunctionsAliases = $this->belongsToManyJunctionAliases($model);
     $keys = ['BelongsTo', 'HasOne', 'HasMany', 'BelongsToMany'];
     $associations = [];
     foreach ($keys as $type) {
         foreach ($model->associations()->type($type) as $assoc) {
             $target = $assoc->target();
             $assocName = $assoc->name();
             $alias = $target->alias();
             //filter existing HasMany
             if ($type === 'HasMany' && in_array($alias, $belongsToManyJunctionsAliases)) {
                 continue;
             }
             $targetClass = get_class($target);
             list(, $className) = namespaceSplit($targetClass);
             $navLink = true;
             $modelClass = get_class($model);
             if ($modelClass !== 'Cake\\ORM\\Table' && $targetClass === $modelClass) {
                 $navLink = false;
             }
             $className = preg_replace('/(.*)Table$/', '\\1', $className);
             if ($className === '') {
                 $className = $alias;
             }
             try {
                 $associations[$type][$assocName] = ['property' => $assoc->property(), 'variable' => Inflector::variable($assocName), 'primaryKey' => (array) $target->primaryKey(), 'displayField' => $target->displayField(), 'foreignKey' => $assoc->foreignKey(), 'alias' => $alias, 'controller' => $className, 'fields' => $target->schema()->columns(), 'navLink' => $navLink];
             } catch (Exception $e) {
                 // Do nothing it could be a bogus association name.
             }
         }
     }
     return $associations;
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:41,代码来源:AssociationFilter.php

示例2: entity

 /**
  * @param array $data
  * @return User
  */
 public function entity(array $data = [])
 {
     $user = new User();
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         $user->{$property} = $value;
     }
     return $user;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:13,代码来源:UserFactory.php

示例3: entity

 /**
  * @param array $data
  * @return Status
  */
 public function entity(array $data = [])
 {
     $status = new Status();
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         $status->{$property} = $value;
     }
     return $status;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:13,代码来源:StatusFactory.php

示例4: entity

 /**
  * @param array $data
  * @return Room
  */
 public function entity(array $data = [])
 {
     $room = new Room();
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         $room->{$property} = $value;
     }
     return $room;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:13,代码来源:RoomFactory.php

示例5: _deriveViewVar

 /**
  * Derive the viewVar based on the scope of the action
  *
  * Actions working on a single entity will use singular name,
  * and actions working on a full table will use plural name
  *
  * @throws Exception
  * @return string
  */
 protected function _deriveViewVar()
 {
     if ($this->scope() === 'table') {
         return Inflector::variable($this->_controller()->name);
     }
     if ($this->scope() === 'entity') {
         return Inflector::variable(Inflector::singularize($this->_controller()->name));
     }
     throw new Exception('Unknown action scope: ' . $this->scope());
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:19,代码来源:ViewVarTrait.php

示例6: startup

 /**
  * {@inheritDoc}
  */
 public function startup()
 {
     $controller = $this->_registry->getController();
     $table = $controller->loadModel();
     $tableAlias = $table->table();
     if (empty($table->enums)) {
         return;
     }
     foreach ($table->enums as $field => $enum) {
         $controller->set(Inflector::pluralize(Inflector::variable($field)), $table->enum($field));
     }
 }
开发者ID:k1low,项目名称:property-enum,代码行数:15,代码来源:AutoSetComponent.php

示例7: entity

 /**
  * @param array $data
  * @return File
  */
 public function entity(array $data = [])
 {
     $userFactory = new UserFactory();
     $file = new File();
     $file->account = $userFactory->entity($data['account']);
     unset($data['account']);
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         $file->{$property} = $value;
     }
     return $file;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:16,代码来源:FileFactory.php

示例8: entity

 /**
  * @param array $data
  * @return Message
  */
 public function entity(array $data = [])
 {
     // @todo ここでnewするのなんとかしたい・・・
     $userFactory = new UserFactory();
     $message = new Message();
     $message->account = $userFactory->entity($data['account']);
     unset($data['account']);
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         $message->{$property} = $value;
     }
     return $message;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:17,代码来源:MessageFactory.php

示例9: _optionsOptions

 protected function _optionsOptions($fieldName, $options)
 {
     $pluralize = true;
     if (substr($fieldName, -5) === '._ids') {
         $fieldName = substr($fieldName, 0, -5);
         $pluralize = false;
     } elseif (substr($fieldName, -3) === '_id') {
         $fieldName = substr($fieldName, 0, -3);
     }
     $fieldName = array_slice(explode('.', $fieldName), -1)[0];
     $varName = Inflector::variable($pluralize ? Inflector::pluralize($fieldName) : $fieldName);
     return $this->_View->get($varName);
 }
开发者ID:leoruhland,项目名称:cakephp-fieldtypes,代码行数:13,代码来源:BootstrapSelectWidget.php

示例10: render

 /**
  * Render action.
  *
  * @return null|string
  */
 public function render()
 {
     $params = $this->_entity->params();
     $links = $this->_getTree();
     $style = Inflector::variable($params->get('style', 'default'));
     if ($style == 'bootstrap') {
         return $this->bootstrapMenu($links);
     }
     if ($style == 'bootstrapDropDown') {
         return $this->bootstrapDropDownMenu($links);
     }
     return $this->defaultMenu($links);
 }
开发者ID:Cheren,项目名称:union_modules,代码行数:18,代码来源:MenusModule.php

示例11: _label

 protected function _label($field)
 {
     if (!isset($this->_properties[$field])) {
         return '';
     }
     $Table = TableRegistry::get($this->_registryAlias);
     $f = Inflector::variable(Inflector::pluralize($field));
     $values = $Table->{$f};
     $value = $this->{$field};
     if (isset($values[$value])) {
         return $values[$value];
     }
     return '';
 }
开发者ID:BreakfastMonkey,项目名称:breakfast-combo,代码行数:14,代码来源:Entity.php

示例12: parse

 /**
  * Parses a string URL into an array. If it matches, it will convert the
  * controller and plugin keys to their CamelCased form and action key to
  * camelBacked form.
  *
  * @param string $url The URL to parse
  * @return array|false An array of request parameters, or false on failure.
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!empty($params['controller'])) {
         $params['controller'] = Inflector::camelize(str_replace('-', '_', $params['controller']));
     }
     if (!empty($params['plugin'])) {
         $params['plugin'] = $this->_camelizePlugin($params['plugin']);
     }
     if (!empty($params['action'])) {
         $params['action'] = Inflector::variable(str_replace('-', '_', $params['action']));
     }
     return $params;
 }
开发者ID:lordsteelhammer,项目名称:cakephp,代码行数:25,代码来源:DashedRoute.php

示例13: publishRelatedModels

 /**
  * Find and publish all related models to the view
  * for an action
  *
  * @param NULL|string $action If NULL the current action will be used
  * @return void
  */
 public function publishRelatedModels($action = null)
 {
     $models = $this->models($action);
     if (empty($models)) {
         return;
     }
     $controller = $this->_controller();
     foreach ($models as $name => $association) {
         list(, $associationName) = pluginSplit($association->name());
         $viewVar = Inflector::variable($associationName);
         if (array_key_exists($viewVar, $controller->viewVars)) {
             continue;
         }
         $query = $association->target()->find('list');
         $subject = $this->_subject(compact('name', 'viewVar', 'query', 'association'));
         $event = $this->_trigger('relatedModel', $subject);
         $controller->set($event->subject->viewVar, $event->subject->query->toArray());
     }
 }
开发者ID:GeBender,项目名称:Teste-DotGroup,代码行数:26,代码来源:RelatedModelsListener.php

示例14: entity

 /**
  * @param array $data
  * @return Task
  */
 public function entity(array $data = [])
 {
     // @todo あとでroomオブジェクトの生成方法とかを見直す
     $roomFactory = new RoomFactory();
     $userFactory = new UserFactory();
     $task = new Task();
     foreach ($data as $key => $value) {
         $property = Inflector::variable($key);
         if ($property == 'room') {
             $task->{$property} = $roomFactory->entity($value);
         } else {
             if ($property == 'assignedByAccount' || $property == 'account') {
                 $task->{$property} = $userFactory->entity($value);
             } else {
                 $task->{$property} = $value;
             }
         }
     }
     return $task;
 }
开发者ID:polidog,项目名称:php-chatwork-api,代码行数:24,代码来源:TaskFactory.php

示例15: _loadController

 /**
  * Loads Controller and sets variables for the template
  * Available template variables:
  *
  * - 'modelClass'
  * - 'primaryKey'
  * - 'displayField'
  * - 'singularVar'
  * - 'pluralVar'
  * - 'singularHumanName'
  * - 'pluralHumanName'
  * - 'fields'
  * - 'keyFields'
  * - 'schema'
  *
  * @return array Returns variables to be made available to a view template
  */
 protected function _loadController()
 {
     $modelObj = TableRegistry::get($this->modelName);
     $tableWithPrefix = $this->Model->getPrefix() . $modelObj->table();
     $modelObj->table($tableWithPrefix);
     $primaryKey = (array) $modelObj->primaryKey();
     $displayField = $modelObj->displayField();
     $singularVar = $this->_singularName($this->controllerName);
     $singularHumanName = $this->_singularHumanName($this->controllerName);
     $schema = $modelObj->schema();
     $fields = $schema->columns();
     $modelClass = $this->modelName;
     $associations = $this->_filteredAssociations($modelObj);
     $keyFields = [];
     if (!empty($associations['BelongsTo'])) {
         foreach ($associations['BelongsTo'] as $assoc) {
             $keyFields[$assoc['foreignKey']] = $assoc['variable'];
         }
     }
     $pluralVar = Inflector::variable($this->controllerName);
     $pluralHumanName = $this->_pluralHumanName($this->controllerName);
     return compact('modelClass', 'schema', 'primaryKey', 'displayField', 'singularVar', 'pluralVar', 'singularHumanName', 'pluralHumanName', 'fields', 'associations', 'keyFields');
 }
开发者ID:ivyhjk,项目名称:autobake,代码行数:40,代码来源:AutoTemplateTask.php


注:本文中的Cake\Utility\Inflector::variable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。