本文整理汇总了PHP中Cake\Utility\Inflector::humanize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::humanize方法的具体用法?PHP Inflector::humanize怎么用?PHP Inflector::humanize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Inflector
的用法示例。
在下文中一共展示了Inflector::humanize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* main
*
*/
public function main()
{
$schemaPo = APP . 'Locale' . DS . 'schema.pot';
$conn = ConnectionManager::get('default');
$collection = $conn->schemaCollection();
$translations = new Translations();
$tables = $collection->listTables();
foreach ($tables as $table) {
$translations->insert($table, Inflector::humanize(Inflector::underscore($table)));
$translations->insert($table, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))));
$columns = $collection->describe($table)->columns();
foreach ($columns as $column) {
$c = $collection->describe($table)->column($column);
$comment = $c['comment'];
$t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore($column)));
$translations[] = $t;
$t->setTranslation($comment);
$t = new Translation($table . '.' . $column, Inflector::humanize(Inflector::underscore(Inflector::singularize($table))) . ' ' . Inflector::humanize(Inflector::underscore($column)));
$translations[] = $t;
$t->setTranslation($comment);
}
}
$poString = $translations->toPoString();
$caked = preg_replace('/msgctxt "([^"]+)"/i', '#: \\1', $poString);
$this->createFile($schemaPo, $caked);
}
示例2: parse
private function parse($json)
{
if (is_array($json)) {
foreach ($json as $item) {
$this->parse($item);
}
} else {
$json = (array) $json;
}
foreach ($json as $tablename => $data) {
if (!is_array($data)) {
$this->parse($data);
} else {
$table = Inflector::tableize($tablename);
$table = $table == 'armours' ? 'armour' : $table;
// Hack for non-standard table names
$table = TableRegistry::get($table);
foreach ($data as $record) {
$record = (array) $record;
$new = $table->import($record);
$result = ['table' => Inflector::humanize($tablename), 'record' => $new->import_name, 'status' => $new->import_action, 'errors' => $new->import_errors];
$this->results[] = $result;
}
}
}
}
示例3: display
/**
* Displays a view
*
* @param mixed What page to display
* @return void
* @throws Cake\Error\NotFoundException When the view file could not be found
* or Cake\View\Error\MissingViewException in debug mode.
*/
public function display()
{
$path = func_get_args();
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = $titleForLayout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$titleForLayout = Inflector::humanize($path[$count - 1]);
}
$this->set(array('page' => $page, 'subpage' => $subpage, 'title_for_layout' => $titleForLayout));
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new Error\NotFoundException();
}
}
示例4: counter
/**
* Returns a counter string for the paged result set
*
* ### Options
*
* - `model` The model to use, defaults to PaginatorHelper::defaultModel();
* - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
* the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any
* custom content you would like.
*
* @param string|array $options Options for the counter string. See #options for list of keys.
* If string it will be used as format.
* @return string Counter string.
* @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter
*/
public function counter($options = [])
{
if (is_string($options)) {
$options = ['format' => $options];
}
$default = ['model' => $this->defaultModel(), 'format' => 'pages'];
$options = \Cake\Utility\Hash::merge($default, $options);
$paging = $this->params($options['model']);
if (!$paging['pageCount']) {
$paging['pageCount'] = 1;
}
$start = 0;
if ($paging['count'] >= 1) {
$start = ($paging['page'] - 1) * $paging['perPage'] + 1;
}
$end = $start + $paging['perPage'] - 1;
if ($paging['count'] < $end) {
$end = $paging['count'];
}
switch ($options['format']) {
case 'range':
case 'pages':
$template = 'counter' . ucfirst($options['format']);
break;
default:
$template = 'counterCustom';
$this->templater()->add([$template => $options['format']]);
}
$map = array_map([$this->Number, 'format'], ['page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, 'end' => $end]);
$map += ['model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))];
return $this->templater()->format($template, $map);
}
示例5: __construct
/**
* Class Constructor
*
* Merges defaults with
* - Configure::read(Meta)
* - Helper options
* - viewVars _meta
* in that order (the latter trumps)
*
* @param array $options
*/
public function __construct(View $View, $options = [])
{
parent::__construct($View, $options);
$configureMeta = (array) Configure::read('Meta');
if (Configure::read('Meta.robots') && is_array(Configure::read('Meta.robots'))) {
$configureMeta['robots'] = Hash::merge($this->meta['robots'], Configure::read('Meta.robots'));
}
$this->meta = $configureMeta + $this->meta;
if (!empty($options['robots']) && is_array($options['robots'])) {
$options['robots'] = Hash::merge($this->meta['robots'], $options['robots']);
}
$this->meta = $options + $this->meta;
if (!empty($this->_View->viewVars['_meta'])) {
$viewVarsMeta = (array) $this->_View->viewVars['_meta'];
if (!empty($viewVarsMeta['robots']) && is_array($viewVarsMeta['robots'])) {
$viewVarsMeta['robots'] = Hash::merge($this->meta['robots'], $viewVarsMeta['robots']);
}
$this->meta = $viewVarsMeta + $this->meta;
}
if ($this->meta['charset'] === null) {
// By default include this
$this->meta['charset'] = true;
}
if ($this->meta['icon'] === null) {
// By default include this
$this->meta['icon'] = true;
}
if ($this->meta['title'] === null) {
$this->meta['title'] = __(Inflector::humanize(Inflector::underscore($this->request->params['controller']))) . ' - ' . __(Inflector::humanize(Inflector::underscore($this->request->params['action'])));
}
}
示例6: renderLayout
public function renderLayout($content, $layout = null)
{
try {
$layout = $this->_getLayoutFileName($layout);
} catch (MissingLayoutException $e) {
$this->_renderLayoutAs = 'string';
}
if (empty($layout)) {
return $this->Blocks->get('content');
}
if (empty($content)) {
$content = $this->Blocks->get('content');
} else {
$this->Blocks->set('content', $content);
}
$this->dispatchEvent('View.beforeLayout', [$layout]);
$title = $this->Blocks->get('title');
if ($title === '') {
$title = Inflector::humanize($this->viewPath);
$this->Blocks->set('title', $title);
}
$this->_currentType = static::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layout));
$this->dispatchEvent('View.afterLayout', [$layout]);
return $this->Blocks->get('content');
}
示例7: _deriveFields
/**
* [_deriveFields description]
*
* @return array
*/
protected function _deriveFields()
{
$table = $this->_table();
$request = $this->_request();
if (!method_exists($table, 'searchConfiguration')) {
return [];
}
$filters = $table->searchConfiguration();
$currentModel = $table->alias();
$schema = $table->schema();
$fields = [];
foreach ($filters->all() as $filter) {
if ($filter->config('form') === false) {
continue;
}
$searchParam = $filter->name();
$field = $filter->field() ?: $searchParam;
// Ignore multi-field filters for now
if (is_array($field)) {
continue;
}
$input = [];
$filterFormConfig = $filter->config();
if (!empty($filterFormConfig['form'])) {
$input = $filterFormConfig['form'];
}
$input += ['label' => Inflector::humanize(preg_replace('/_id$/', '', $searchParam)), 'required' => false, 'type' => 'text'];
$value = $request->query($searchParam);
if ($value !== null) {
$input['value'] = $value;
}
if (empty($input['options']) && $table->hasField($field)) {
if ($schema->columnType($field) === 'boolean') {
$input['options'] = ['No', 'Yes'];
$input['type'] = 'select';
}
}
if (!empty($input['options'])) {
$input['empty'] = true;
$fields[$searchParam] = $input;
continue;
}
if (empty($input['class'])) {
$input['class'] = 'autocomplete';
}
if (empty($input['type'])) {
$input['type'] = 'text';
}
$urlArgs = [];
$fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
foreach ($fieldKeys as $key => $val) {
$urlArgs[$key] = $val;
}
unset($input['fields']);
$url = ['action' => 'lookup', '?' => $urlArgs, '_ext' => 'json'];
$input['data-url'] = Router::url($url);
$fields[$searchParam] = $input;
}
return $fields;
}
示例8: getActionName
public function getActionName($controller, $id)
{
$this->autoRender = false;
$indexed_tables = $this->_getIndexedTables();
if (isset($indexed_tables[$controller][$id])) {
echo $indexed_tables[$controller][$id] . ' (' . __(Inflector::humanize(Inflector::underscore($controller))) . ' / ' . $id . ')';
}
}
示例9: _defaultInput
/**
* Generates default input for parameter
*
* @param BaseParameter $param Form parameter.
* @return array
*/
protected function _defaultInput($param)
{
$input = $param->formInputConfig();
$name = $param->config('name');
$input += ['type' => 'text', 'required' => false, 'label' => Inflector::humanize(preg_replace('/_id$/', '', $name))];
if (!$param->visible()) {
$input['type'] = 'hidden';
}
return $input;
}
示例10: beforeSave
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
{
if (empty($entity->display)) {
$entity->display = Inflector::humanize($entity->name);
}
if ($entity->dirty('is_default') && $entity->is_default) {
$this->updateAll(['is_default' => false], ['is_default' => true]);
} elseif ($entity->dirty('is_default') && !$entity->is_default) {
$entity->is_default = $entity->getOriginal('is_default');
}
}
示例11: _deriveFields
/**
* [_deriveFields description]
*
* @return array
*/
protected function _deriveFields()
{
$table = $this->_table();
$request = $this->_request();
$filters = null;
if (method_exists($table, 'searchConfiguration')) {
$filters = $table->searchConfiguration();
} else {
$filters = $table->searchManager();
}
$fields = [];
$schema = $table->schema();
$config = $this->_config;
foreach ($filters->all() as $filter) {
if ($filter->config('form') === false) {
continue;
}
$field = $filter->name();
$input = [];
$filterFormConfig = $filter->config();
if (!empty($filterFormConfig['form'])) {
$input = $filterFormConfig['form'];
}
$input += ['label' => Inflector::humanize(preg_replace('/_id$/', '', $field)), 'required' => false, 'type' => 'text'];
$input['value'] = $request->query($field);
if (empty($input['options']) && $schema->columnType($field) === 'boolean') {
$input['options'] = ['No', 'Yes'];
$input['type'] = 'select';
}
if (!empty($input['options'])) {
$input['empty'] = true;
if (empty($input['class']) && !$config['selectize']) {
$input['class'] = 'no-selectize';
}
$fields[$field] = $input;
continue;
}
if (empty($input['class']) && $config['autocomplete']) {
$input['class'] = 'autocomplete';
}
$urlArgs = [];
$fieldKeys = isset($input['fields']) ? $input['fields'] : ['id' => $field, 'value' => $field];
foreach ($fieldKeys as $key => $val) {
$urlArgs[$key] = $val;
}
unset($input['fields']);
$url = array_merge(['action' => 'lookup', '_ext' => 'json'], $urlArgs);
$input['data-url'] = Router::url($url);
$fields[$field] = $input;
}
return $fields;
}
示例12: display
/**
* Displays a help file formatted in markdown.
* Original method from CakePHP's PagesController file.
*
* @param mixed What page to display
* @return void
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public function display()
{
$this->viewClass = 'Sb.Markdown';
// Layout
if (!Configure::read('Sb.Croogo')) {
$this->layout = 'doc';
} else {
$this->layout = 'doc_croogo';
}
$path = func_get_args();
$docs = null;
if (!empty($this->request->params['named']['docs'])) {
$docs = $this->request->params['named']['docs'];
}
$base = null;
// If you want to add other pathes, don't forget to add a trailing '::'
switch ($docs) {
case 'template':
$base = Plugin::path('Sb') . 'template/docs::';
break;
default:
$base = Plugin::path('Sb') . 'docs::';
break;
}
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
try {
$this->render($base . implode('/', $path), null);
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
示例13: initialize
/**
*
*/
public function initialize()
{
parent::initialize();
/**
* Use Builder Helpers
*/
$this->loadHelper('Flash', ['className' => 'Builder.Flash']);
/**
* Set default layout for App using Layout/builder
*/
if ($this->layout === 'default') {
$this->layout('builder/default');
}
/**
* Set form templates
*/
$_templates = ['dateWidget' => '<ul class="list-inline"><li class="year">{{year}}</li><li class="month">{{month}}</li><li class="day">{{day}}</li><li class="hour">{{hour}}</li><li class="minute">{{minute}}</li><li class="second">{{second}}</li><li class="meridian">{{meridian}}</li></ul>', 'error' => '<div class="help-block">{{content}}</div>', 'help' => '<div class="help-block">{{content}}</div>', 'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}{{help}}</div>', 'inputContainerError' => '<div class="form-group {{type}}{{required}} has-error">{{content}}{{error}}{{help}}</div>', 'checkboxWrapper' => '<div class="checkbox"><label>{{input}}{{label}}</label></div>', 'multipleCheckboxWrapper' => '<div class="checkbox">{{label}}</div>', 'radioInlineFormGroup' => '{{label}}<div class="radio-inline-wrapper">{{input}}</div>', 'radioNestingLabel' => '<div class="radio">{{hidden}}<label{{attrs}}>{{input}}{{text}}</label></div>', 'staticControl' => '<p class="form-control-static">{{content}}</p>', 'inputGroupAddon' => '<span class="{{class}}">{{content}}</span>', 'inputGroupContainer' => '<div class="input-group">{{prepend}}{{content}}{{append}}</div>', 'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>', 'textarea' => '<textarea class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>', 'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>', 'selectMultiple' => '<select class="form-control" name="{{name}}[]" multiple="multiple"{{attrs}}>{{content}}</select>'];
/**
*
*/
$this->Form->templates($_templates);
/**
* Loader base styles using bower_components and default Builder settings
*/
$this->start('builder-css');
echo $this->Html->css(['/bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css', '/bower_components/bootstrap/dist/css/bootstrap.min.css', '/bower_components/fontawesome/css/font-awesome.min.css', '/bower_components/datatables/media/css/dataTables.bootstrap.min.css', '/bower_components/summernote/dist/summernote.css', '/css/builder/base.css']);
$this->end();
/**
* Laoder base scripts using bower_components and default Builder settings
*/
$this->start('builder-script');
echo $this->Html->script(['/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery-ui/jquery-ui.min.js', '/bower_components/bootstrap/dist/js/bootstrap.min.js', '/bower_components/datatables/media/js/jquery.dataTables.min.js', '/bower_components/datatables/media/js/dataTables.bootstrap.js', '/bower_components/summernote/dist/summernote.min.js', '/js/builder/base.js']);
$this->end();
/**
* Load Builder default constructor element form Builder/Element/constructor
*/
$this->prepend('builder-element', $this->element('Builder.constructor/default'));
/**
* If empty 'nav' block, set default navbar using Builder/Element/builder
*/
if (!$this->fetch('nav')) {
$this->assign('nav', $this->element('Builder.builder/navbar-fixed-top'));
}
/**
* Set default title for layout using controller name
*/
$this->assign('title', Inflector::humanize(Inflector::tableize($this->request->controller)));
}
示例14: groupName
/**
* Method that converts Controller
* full name to human readable label
* @param string $name Controller full name
* @return void
*/
public function groupName($name)
{
$parts = array_map(function ($n) {
return Inflector::humanize(Inflector::underscore(str_replace('Controller', '', $n)));
}, explode('\\', $name));
/*
removes empty array entries
*/
$parts = array_filter($parts);
/*
get just the controller and plugin names
*/
$parts = array_slice($parts, -2);
$name = implode(' :: ', $parts);
$this->set('groupName', $name);
}
示例15: nestedListFormat
/**
* Format nested list element
*
* Callback method used by The NestableHelper
*
* @param array $data NestableHelper configuration
* @param \Cake\ORM\Entity $entity Entity to format
*/
public function nestedListFormat(array $data, Entity $entity)
{
$displayField = TableRegistry::get($entity->source())->displayField();
$html = '<span class="pull-right p10 pb5">';
$html .= $this->Html->link('<i class="fa fa-edit"></i> ', ['action' => 'edit', $entity->id], ['class' => '', 'escape' => false, 'title' => __d('admin', 'Edit')]);
$html .= $this->Form->postLink('<i class="fa fa-trash-o"></i>', ['action' => 'delete', $entity['id']], ['class' => '', 'title' => __d('admin', 'Delete {0}', Inflector::humanize($entity->source)), 'escape' => false, 'confirm' => __d('admin', 'Are you sure you want to delete #{0} {1}?', $entity->id, $entity->{$displayField})]);
$html .= '</span>';
$html .= '<div class="dd-handle" data-id="' . $entity->id . '">';
if ($entity->active === false) {
$html .= '<span class="text-muted">' . $entity->{$displayField} . '</span>';
$html .= ' <span class="text-danger"><i class="fa fa-ban"></i><em class="sr-only">Non active</em></span>';
} else {
$html .= $entity->{$displayField};
}
$html .= '</div>';
return $html;
}