本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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 '';
}
示例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;
}
示例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());
}
}
示例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;
}
示例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');
}