本文整理汇总了PHP中Cake\Utility\Inflector::tableize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::tableize方法的具体用法?PHP Inflector::tableize怎么用?PHP Inflector::tableize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Inflector
的用法示例。
在下文中一共展示了Inflector::tableize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: templateData
/**
* Get template data.
*
* @return array
*/
public function templateData()
{
$namespace = Configure::read('App.namespace');
if ($this->plugin) {
$namespace = $this->_pluginNamespace($this->plugin);
}
$table = Inflector::tableize($this->args[0]);
if (!empty($this->params['table'])) {
$table = $this->params['table'];
}
$records = false;
if ($this->param('data')) {
$limit = (int) $this->param('limit');
$fields = $this->param('fields') ?: '*';
if ($fields !== '*') {
$fields = explode(',', $fields);
}
$connection = ConnectionManager::get($this->connection);
$query = $connection->newQuery()->from($table)->select($fields);
if ($limit) {
$query->limit($limit);
}
$records = $connection->execute($query)->fetchAll('assoc');
$records = $this->prettifyArray($records);
}
return ['className' => $this->BakeTemplate->viewVars['name'], 'namespace' => $namespace, 'records' => $records, 'table' => $table];
}
示例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: 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);
}
示例4: main
public function main($name = null)
{
$table = Inflector::tableize($name);
$prefix = $this->AutoModel->getPrefix();
$newName = preg_replace('/' . $prefix . '/i', '', $table);
// debug(compact('newName', 'table', 'prefix', 'name'));
// exit();
parent::main($newName);
}
示例5: templateData
/**
* Get template data.
*
* @return array
*/
public function templateData()
{
$namespace = Configure::read('App.namespace');
if ($this->plugin) {
$namespace = $this->_pluginNamespace($this->plugin);
}
$table = Inflector::tableize($this->args[0]);
if (!empty($this->params['table'])) {
$table = $this->params['table'];
}
return ['className' => $this->BakeTemplate->viewVars['name'], 'namespace' => $namespace, 'records' => false, 'table' => $table];
}
示例6: _getVars
/**
* Returns variables for bake template.
*
* @param string $actionName action name
* @return array
*/
protected function _getVars($actionName)
{
$action = $this->detectAction($actionName);
if (empty($action)) {
$table = $actionName;
$action = 'create_table';
} else {
list($action, $table) = $action;
}
$table = Inflector::tableize($table);
$name = Inflector::camelize($actionName) . $this->_getLastModifiedTime($table);
return [$action, $table, $name];
}
示例7: 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)));
}
示例8: _modifyEntity
/**
* Modify entity
*
* @param \Cake\Datasource\EntityInterface entity
* @param \Cake\ORM\Association table
* @param string path prefix
* @return void
*/
protected function _modifyEntity(EntityInterface $entity, Association $table = null, $pathPrefix = '')
{
if (is_null($table)) {
$table = $this->_table;
}
// unset primary key
unset($entity->{$table->primaryKey()});
// unset foreign key
if ($table instanceof Association) {
unset($entity->{$table->foreignKey()});
}
// unset configured
foreach ($this->config('remove') as $field) {
$field = $this->_fieldByPath($field, $pathPrefix);
if ($field) {
unset($entity->{$field});
}
}
// set / prepend / append
foreach (['set', 'prepend', 'append'] as $action) {
foreach ($this->config($action) as $field => $value) {
$field = $this->_fieldByPath($field, $pathPrefix);
if ($field) {
if ($action == 'prepend') {
$value .= $entity->{$field};
}
if ($action == 'append') {
$value = $entity->{$field} . $value;
}
$entity->{$field} = $value;
}
}
}
// set as new
$entity->isNew(true);
// modify related entities
foreach ($this->config('contain') as $contain) {
if (preg_match('/^' . preg_quote($pathPrefix, '/') . '([^.]+)/', $contain, $matches)) {
foreach ($entity->{Inflector::tableize($matches[1])} as $related) {
if ($related->isNew()) {
continue;
}
$this->_modifyEntity($related, $table->{$matches[1]}, $pathPrefix . $matches[1] . '.');
}
}
}
}
示例9: init
/**
* Initialize the fixture.
*
* @return void
* @throws \Cake\ORM\Exception\MissingTableClassException When importing from a table that does not exist.
*/
public function init()
{
if ($this->table === null) {
list(, $class) = namespaceSplit(get_class($this));
preg_match('/^(.*)Fixture$/', $class, $matches);
$table = $class;
if (isset($matches[1])) {
$table = $matches[1];
}
$this->table = Inflector::tableize($table);
}
if (empty($this->import) && !empty($this->fields)) {
$this->_schemaFromFields();
}
if (!empty($this->import)) {
$this->_schemaFromImport();
}
}
示例10: getUploadPath
public function getUploadPath(Entity $entity, $path, $extension)
{
$replace = array('%uuid' => String::uuid(), '%id' => $entity->id, '%y' => date('Y'), '%m' => date('m'), '/' => DS);
$path = $this->_config['assets_dir'] . DS . Inflector::tableize($entity->source()) . DS . strtr($path, $replace) . '.' . $extension;
return $path;
}
示例11: getViewManager
/**
* 获取ViewManager
* @return ViewManager
*/
public function getViewManager()
{
if (is_null($this->viewManager)) {
$controller = $this->getKernel()->getParameter('controller');
$controllerDir = Inflector::tableize(substr($controller, 0, -10));
$viewManager = $this->getKernel()->getContainer()->get('view');
$viewManager->setViewPath($this->getViewPath() . "/templates/{$controllerDir}/");
$viewManager->setLayoutPath($this->getViewPath() . '/layouts/');
$this->viewManager = $viewManager;
}
return $this->viewManager;
}
示例12: _tableFromClass
/**
* Returns the table name using the fixture class
*
* @return string
*/
protected function _tableFromClass()
{
list(, $class) = namespaceSplit(get_class($this));
preg_match('/^(.*)Fixture$/', $class, $matches);
$table = $class;
if (isset($matches[1])) {
$table = $matches[1];
}
return Inflector::tableize($table);
}
示例13: getMockForModel
/**
* Mock a model, maintain fixtures and table association
*
* @param string $alias The model to get a mock for.
* @param mixed $methods The list of methods to mock
* @param array $options The config data for the mock's constructor.
* @throws \Cake\ORM\Exception\MissingTableClassException
* @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
*/
public function getMockForModel($alias, array $methods = [], array $options = [])
{
if (empty($options['className'])) {
$class = Inflector::camelize($alias);
$className = App::className($class, 'Model/Table', 'Table');
if (!$className) {
throw new MissingTableClassException([$alias]);
}
$options['className'] = $className;
}
$connectionName = $options['className']::defaultConnectionName();
$connection = ConnectionManager::get($connectionName);
list(, $baseClass) = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += TableRegistry::config($alias);
$mock = $this->getMockBuilder($options['className'])->setMethods($methods)->setConstructorArgs([$options])->getMock();
if (empty($options['entityClass']) && $mock->entityClass() === '\\Cake\\ORM\\Entity') {
$parts = explode('\\', $options['className']);
$entityAlias = Inflector::singularize(substr(array_pop($parts), 0, -5));
$entityClass = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $entityAlias;
if (class_exists($entityClass)) {
$mock->entityClass($entityClass);
}
}
if (stripos($mock->table(), 'mock') === 0) {
$mock->table(Inflector::tableize($baseClass));
}
TableRegistry::set($baseClass, $mock);
TableRegistry::set($alias, $mock);
return $mock;
}
示例14: _getAvailableRoles
/**
* Returns a list of all available roles. Will look for a roles array in
* Configure first, tries database roles table next.
*
* @return array List with all available roles
* @throws Cake\Core\Exception\Exception
*/
protected function _getAvailableRoles()
{
$roles = Configure::read($this->_config['rolesTable']);
if (is_array($roles)) {
return $roles;
}
// no roles in Configure AND rolesTable does not exist
$tables = ConnectionManager::get('default')->schemaCollection()->listTables();
if (!in_array(Inflector::tableize($this->_config['rolesTable']), $tables)) {
throw new Exception('Invalid TinyAuthorize Role Setup (no roles found in Configure or database)');
}
// fetch roles from database
$rolesTable = TableRegistry::get($this->_config['rolesTable']);
$roles = $rolesTable->find('all')->formatResults(function ($results) {
return $results->combine('alias', 'id');
})->toArray();
if (!count($roles)) {
throw new Exception('Invalid TinyAuthorize Role Setup (rolesTable has no roles)');
}
return $roles;
}
示例15: detectAction
/**
* Detects the action and table from the name of a migration
*
* @param string $name Name of migration
* @return array
**/
public function detectAction($name)
{
if (preg_match('/^(Create|Drop)(.*)/', $name, $matches)) {
$action = strtolower($matches[1]) . '_table';
$table = Inflector::tableize(Inflector::pluralize($matches[2]));
} elseif (preg_match('/^(Add).+?(?:To)(.*)/', $name, $matches)) {
$action = 'add_field';
$table = Inflector::tableize(Inflector::pluralize($matches[2]));
} elseif (preg_match('/^(Remove).+?(?:From)(.*)/', $name, $matches)) {
$action = 'drop_field';
$table = Inflector::tableize(Inflector::pluralize($matches[2]));
} elseif (preg_match('/^(Alter)(.*)/', $name, $matches)) {
$action = 'alter_table';
$table = Inflector::tableize(Inflector::pluralize($matches[2]));
} else {
return [];
}
return [$action, $table];
}