本文整理汇总了PHP中Cake\Utility\Inflector::dasherize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::dasherize方法的具体用法?PHP Inflector::dasherize怎么用?PHP Inflector::dasherize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Inflector
的用法示例。
在下文中一共展示了Inflector::dasherize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
/**
* Before render callback.
*
* @param \Cake\Event\Event $event The beforeRender event.
* @return void
*/
public function beforeRender(Event $event)
{
parent::beforeRender($event);
$params = $this->request->params;
$page_id = Inflector::dasherize(implode('-', array_merge([$params['controller']], $params['pass'])));
$this->set(compact('page_id'));
}
示例2: _renderInputWithData
/**
* Renders new file input field with value. Applicable for edit action.
*
* @param Table $table Table
* @param string $field Field
* @param array $options Options
* @param mixed $data Data
* @return string HTML input field with data attribute.
*/
protected function _renderInputWithData($table, $field, $data, $options)
{
$files = [];
$hiddenIds = '';
$fieldName = $this->_getFieldName($table, $field);
$fileUploadsUtils = new FileUploadsUtils($table);
$entities = $fileUploadsUtils->getFiles($table, $field, $data);
if ($entities instanceof \Cake\ORM\ResultSet) {
if (!$entities->count()) {
return $this->_renderInputWithoutData($table, $field, $options);
}
}
// @TODO: check if we return null anywhere, apart of ResultSet.
// IF NOT: remove this block
if (is_null($entities)) {
return $this->_renderInputWithoutData($table, $field, $options);
}
foreach ($entities as $file) {
$files[] = ['id' => $file->id, 'path' => $file->path];
$hiddenIds .= $this->cakeView->Form->hidden($this->_getFieldName($table, $field, $options) . '_ids][', ['class' => str_replace('.', '_', $fieldName . '_ids'), 'value' => $file->id]);
}
$label = $this->cakeView->Form->label($field);
$uploadField = $this->cakeView->Form->file($fieldName . '[]', ['multiple' => true, 'data-document-id' => $data, 'data-upload-url' => sprintf("/api/%s/upload", Inflector::dasherize($table->table())), 'data-files' => json_encode($files)]);
return sprintf(self::WRAPPER, $label, $uploadField, $hiddenIds);
}
示例3: bodyCssClass
public function bodyCssClass()
{
$page = WasabiCms::page();
$classes = [];
$classes[] = 'layout-' . Inflector::dasherize($page->layout);
$classes[] = 'page-' . Inflector::dasherize($page->slug);
return implode(' ', $classes);
}
示例4: _dasherize
/**
* Helper method for dasherizing keys in a URL array.
*
* @param array $url An array of URL keys.
* @return array
*/
protected function _dasherize($url)
{
foreach (['controller', 'plugin', 'action'] as $element) {
if (!empty($url[$element])) {
$url[$element] = Inflector::dasherize($url[$element]);
}
}
return $url;
}
示例5: nameTransaction
/**
* nameTransaction() method.
*
* Name the transaction using request data.
*
* @param Cake\Network\Network $request The request.
* @return string
*/
public function nameTransaction(Request $request)
{
$plugin = $request->params['plugin'];
$prefix = $request->params['prefix'];
$controller = $request->params['controller'];
$action = $request->params['action'];
$transaction = Inflector::dasherize($controller) . '/' . $action;
if ($prefix !== null) {
$transaction = Inflector::dasherize($prefix) . '/' . $transaction;
}
if ($plugin !== null) {
$transaction = Inflector::dasherize($plugin) . '/' . $transaction;
}
return $transaction;
}
示例6: _generateFiles
/**
* Generate all files for a plugin
*
* Find the first path which contains `src/Template/Bake/Plugin` that contains
* something, and use that as the template to recursively render a plugin's
* contents. Allows the creation of a bake them containing a `Plugin` folder
* to provide customized bake output for plugins.
*
* @param string $pluginName the CamelCase name of the plugin
* @param string $path the path to the plugins dir (the containing folder)
* @return void
*/
protected function _generateFiles($pluginName, $path)
{
$namespace = str_replace('/', '\\', $pluginName);
$name = $pluginName;
$vendor = 'your-name-here';
if (strpos($pluginName, '/') !== false) {
list($vendor, $name) = explode('/', $pluginName);
}
$package = $vendor . '/' . $name;
$this->BakeTemplate->set(['package' => $package, 'namespace' => $namespace, 'plugin' => $pluginName, 'routePath' => Inflector::dasherize($pluginName), 'path' => $path, 'root' => ROOT]);
$root = $path . $pluginName . DS;
$paths = [];
if (!empty($this->params['theme'])) {
$paths[] = Plugin::path($this->params['theme']) . 'src/Template/';
}
$paths = array_merge($paths, Configure::read('App.paths.templates'));
$paths[] = Plugin::path('Bake') . 'src/Template/';
do {
$templatesPath = array_shift($paths) . 'Bake/Plugin';
$templatesDir = new Folder($templatesPath);
$templates = $templatesDir->findRecursive('.*\\.ctp');
} while (!$templates);
sort($templates);
foreach ($templates as $template) {
$template = substr($template, strrpos($template, 'Plugin') + 7, -4);
$this->_generateFile($template, $root);
}
}
示例7: testDasherized
/**
* testDasherized method
*
* @return void
*/
public function testDasherized()
{
$this->assertSame('test-thing', Inflector::dasherize('TestThing'));
$this->assertSame('test-thing', Inflector::dasherize('testThing'));
$this->assertSame('test-thing-extra', Inflector::dasherize('TestThingExtra'));
$this->assertSame('test-thing-extra', Inflector::dasherize('testThingExtra'));
$this->assertSame('test-this-thing', Inflector::dasherize('test_this_thing'));
// Test stupid values
$this->assertSame('', Inflector::dasherize(null));
$this->assertSame('', Inflector::dasherize(''));
$this->assertSame('0', Inflector::dasherize(0));
$this->assertSame('', Inflector::dasherize(false));
}
示例8: __setPhoneKeys
/**
* @return void
*/
private function __setPhoneKeys()
{
$keys = [];
foreach ($this->_fieldsName['phone'] as $key) {
$inflectored = [Inflector::camelize($key), Inflector::dasherize($key), Inflector::underscore($key), Inflector::variable($key)];
foreach ($inflectored as $field) {
// Default Version
$keys[$field] = $field;
// strtolower
$keys[strtolower($key)] = strtolower($key);
// strtoupper
$keys[strtoupper($key)] = strtoupper($key);
}
}
$this->_fields['phone'] = $keys;
}
示例9: _getPrefix
/**
* Get the prefix for a namespace.
*
* @param string|null $namespace The namespace to get a prefix from.
* @return string|null
*/
protected function _getPrefix($namespace = null)
{
if (empty($namespace)) {
return null;
}
$pathArray = explode('\\', $namespace);
if (count($pathArray) >= 5 && $pathArray[3] !== 'Controller') {
return Inflector::dasherize($pathArray[3]) . '_';
}
return null;
}
示例10: beforeRender
/**
* Before render callback.
*
* @param \Cake\Event\Event $event The beforeRender event.
* @return void
*/
public function beforeRender(Event $event)
{
if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml'])) {
$this->set('_serialize', true);
}
$viewVars = [];
$params = $this->request->params;
if ($params['controller'] !== 'Pages') {
$page_id = Inflector::dasherize($params['controller'] . '-' . $params['action']);
$viewVars[] = 'page_id';
}
if ($user = $this->Auth->user()) {
$user = TableRegistry::get('Users')->get($user['id']);
$viewVars[] = 'user';
}
$this->set(compact($viewVars));
}
示例11: resourceKey
/**
* Return resource key.
*
* @param string $name Name.
* @return string
*/
public function resourceKey($name)
{
return Inflector::pluralize(Inflector::dasherize($name));
}