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


PHP Inflector::slug方法代码示例

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


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

示例1: beforeDispatch

 /**
  * Checks whether the response was cached and set the body accordingly.
  *
  * @param \Cake\Event\Event $event containing the request and response object
  * @return \Cake\Network\Response with cached content if found, null otherwise
  */
 public function beforeDispatch(Event $event)
 {
     if (Configure::read('Cache.check') !== true) {
         return;
     }
     $path = $event->data['request']->here();
     if ($path === '/') {
         $path = 'home';
     }
     $prefix = Configure::read('Cache.viewPrefix');
     if ($prefix) {
         $path = $prefix . '_' . $path;
     }
     $path = strtolower(Inflector::slug($path));
     $filename = CACHE . 'views/' . $path . '.php';
     if (!file_exists($filename)) {
         $filename = CACHE . 'views/' . $path . '_index.php';
     }
     if (file_exists($filename)) {
         $controller = null;
         $view = new View($controller);
         $view->response = $event->data['response'];
         $result = $view->renderCache($filename, microtime(true));
         if ($result !== false) {
             $event->stopPropagation();
             $event->data['response']->body($result);
             return $event->data['response'];
         }
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:36,代码来源:CacheDispatcher.php

示例2: _getNodeCacheKey

 /**
  * Generates a key string to use for the cache
  *
  * @param string|array|Entity $ref Array with 'model' and 'foreign_key', model object, or string value
  * @return string
  */
 protected function _getNodeCacheKey($ref)
 {
     if (empty($ref)) {
         return '';
     } elseif (is_string($ref)) {
         return Inflector::slug($ref, '_');
     } elseif (is_object($ref) && $ref instanceof Entity) {
         return $ref->source() . '_' . $ref->id;
     } elseif (is_array($ref) && !(isset($ref['model']) && isset($ref['foreign_key']))) {
         $name = key($ref);
         list(, $alias) = pluginSplit($name);
         $bindTable = TableRegistry::get($name);
         $entityClass = $bindTable->entityClass();
         if ($entityClass) {
             $entity = new $entityClass();
         }
         if (empty($entity)) {
             throw new Exception\Exception(__d('cake_dev', "Entity class {0} not found in CachedDbAcl::_getNodeCacheKey() when trying to bind {1} object", [$type, $this->alias()]));
         }
         $tmpRef = null;
         if (method_exists($entity, 'bindNode')) {
             $tmpRef = $entity->bindNode($ref);
         }
         if (empty($tmpRef)) {
             $ref = ['model' => $alias, 'foreign_key' => $ref[$name][$bindTable->primaryKey()]];
         } else {
             $ref = $tmpRef;
         }
         return $ref['model'] . '_' . $ref['foreign_key'];
     } elseif (is_array($ref)) {
         return $ref['model'] . '_' . $ref['foreign_key'];
     }
     return '';
 }
开发者ID:edukondaluetg,项目名称:acl,代码行数:40,代码来源:CachedDbAcl.php

示例3: _save

 /**
  *
  *
  * FUNCTIONS PRIVATE
  *
  */
 private function _save($entity)
 {
     if ($this->request->is(['patch', 'post', 'put'])) {
         $entity = $this->Contentbuilders->patchEntity($entity, $this->request->data);
         // On ajoute les traductions
         $I18ns = TableRegistry::get('I18ns');
         $langs = $I18ns->find('list', ['keyField' => 'id', 'valueField' => 'locale'])->toArray();
         // On merge nos translations
         if (isset($entity->translations)) {
             $entity->_translations = array_merge($entity->_translations, $entity->translations);
             unset($entity->translations);
         }
         foreach ($entity->_translations as $lang => $data) {
             if (in_array($lang, $langs)) {
                 if ($entity->type_id !== Type::TYPE_HOMEPAGE && empty($data['slug']) && !empty($data['title'])) {
                     $data['slug'] = strtolower(Inflector::slug($data['title']));
                     // @ TODO : Il faudra penser a vérifier que le slug n'existe pas, sinon on rajoute -x
                 }
                 $entity->translation($lang)->set($data, ['guard' => false]);
             }
         }
         if ($this->Contentbuilders->save($entity)) {
             $this->set('response', [true, __("Object saved with success !"), Router::url(['controller' => 'Contentbuilders', 'action' => 'edit', $entity->id, '_ext' => 'html'])]);
             $this->set('_serialize', 'response');
         } else {
             $this->set('response', [false, __("Error occured while saving object !"), $entity->errors()]);
             $this->set('_serialize', 'response');
         }
     }
     $types = Contentbuilder::getPrettyType();
     $parents = $this->Contentbuilders->find('treeList', ['keyPath' => 'id', 'valuePath' => 'label', 'spacer' => ' --- ']);
     $this->set(compact('entity', 'types', 'parents'));
 }
开发者ID:Aerue,项目名称:avalia,代码行数:39,代码来源:ContentbuildersController.php

示例4: edit

 public function edit($id = null)
 {
     $page = $this->Pages->get($id, ['contain' => []]);
     if ($this->request->is(['patch', 'post', 'put'])) {
         $page = $this->Pages->patchEntity($page, $this->request->data);
         //VARAIALBES
         $title = $this->request->data['title'];
         $templateName = $this->request->data['templatename'];
         // strToLower UTF8
         $title = mb_strtolower($title, 'UTF-8');
         $title = ucfirst($title);
         $templateName = mb_strtolower($templateName, 'UTF-8');
         //SLUGIFY
         $slug = Inflector::slug(mb_strtolower($title, 'UTF-8'), '-');
         $templateName = Inflector::slug(mb_strtolower($templateName, 'UTF-8'), '_');
         //SAUVEGARDE DES MODIFICATIONS
         $page->title = $title;
         $page->slug = $slug;
         $page->templatename = $templateName;
         if ($this->Pages->save($page)) {
             $this->Flash->success(__('The page has been saved.'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__('The page could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('page'));
     $this->set('_serialize', ['page']);
 }
开发者ID:Raphai,项目名称:shaka,代码行数:29,代码来源:PagesController.php

示例5: article_edit

 public function article_edit($id = null)
 {
     //LOAD CATEGORIES
     $this->loadModel('Categories');
     $categories = $this->Categories->find('list');
     $this->set(compact('categories'));
     $article = $this->Article->get($id);
     $this->set('title_for_layout', $article->title);
     $featured_image = $article->featured;
     if (empty($article)) {
         throw new NotFoundException('Could not find that article.');
     } else {
         $this->set(compact('article'));
     }
     if ($this->request->is(['post', 'put'])) {
         $this->Article->patchEntity($article, $this->request->data);
         $article->slug = strtolower(Inflector::slug($article->title));
         if (!empty($this->request->data['featured']['name'])) {
             $file = $this->request->data['featured'];
             move_uploaded_file($file['tmp_name'], WWW_ROOT . 'img/articles/featured/' . $file['name']);
             $article->featured = $file['name'];
         } else {
             $article->featured = $featured_image;
         }
         if ($this->Article->save($article)) {
             $this->Flash->success(__('The article has been updated.'));
             return $this->redirect("" . Configure::read('BASE_URL') . "/admin/articles");
         }
         $this->Flash->error(__('Unable to edit article.'));
     }
 }
开发者ID:keremcankaya0,项目名称:CakeBlog,代码行数:31,代码来源:ArticlesController.php

示例6: _domId

 /**
  * Generate an ID suitable for use in an ID attribute.
  *
  * @param string $value The value to convert into an ID.
  * @return string The generated id.
  */
 protected function _domId($value)
 {
     $domId = mb_strtolower(Inflector::slug($value, '-'));
     if (!empty($this->_idPrefix)) {
         $domId = $this->_idPrefix . '-' . $domId;
     }
     return $domId;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:14,代码来源:IdGeneratorTrait.php

示例7: _setSlug

 protected function _setSlug($value)
 {
     debug($this);
     if (empty($value)) {
         return Inflector::slug($this->name);
     }
     return $value;
 }
开发者ID:ThomasCHICHEPORTICHE,项目名称:cake_blog,代码行数:8,代码来源:Category.php

示例8: slug

 /**
  * Generate slug.
  *
  * @param string $string Input string.
  * @param string $replacement Replacement string.
  * @return string Sluggified string.
  */
 public function slug($string, $replacement = '-')
 {
     $string = Inflector::slug($string, $replacement);
     if ($this->config['lowercase']) {
         return strtolower($string);
     }
     return $string;
 }
开发者ID:kwadwo,项目名称:Slug,代码行数:15,代码来源:CakeSlugger.php

示例9: init

 /**
  * Initialize the Cache Engine
  *
  * Called automatically by the cache frontend
  *
  * @param array $config array of setting for the engine
  * @return bool True if the engine has been successfully initialized, false if not
  */
 public function init(array $config = [])
 {
     if (!isset($config['prefix'])) {
         $config['prefix'] = Inflector::slug(APP_DIR) . '_';
     }
     parent::init($config);
     return function_exists('apc_dec');
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:16,代码来源:ApcEngine.php

示例10: _setSlug

 protected function _setSlug($slug)
 {
     if ($slug !== '') {
         $slug = Inflector::slug($slug);
         return $slug;
     }
     return $this->get('slug');
 }
开发者ID:cakemanager,项目名称:cakeadmin-cms,代码行数:8,代码来源:Blog.php

示例11: getClasses

 /**
  * Get classes for main wrapper.
  *
  * @return string
  */
 public function getClasses()
 {
     $plugin = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->request->param('plugin'));
     $plugin = Inflector::underscore($plugin);
     $controller = mb_strtolower($this->request->param('controller'));
     $action = mb_strtolower($this->request->param('action'));
     return implode(' ', ['plg-' . Inflector::slug($plugin, '-'), 'cont-' . $controller, 'action-' . $action]);
 }
开发者ID:Cheren,项目名称:union,代码行数:13,代码来源:DocumentHelper.php

示例12: slug

 public function slug(Entity $entity)
 {
     $config = $this->config();
     if (!($value = $entity->get($config['slug']))) {
         $value = $entity->get($config['field']);
     }
     $entity->set($config['slug'], Inflector::slug($value, $config['replacement']));
 }
开发者ID:esaul314,项目名称:norn-cms,代码行数:8,代码来源:SluggableBehavior.php

示例13: beforeSave

 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->config();
     $value = $entity->get($config['field']);
     $id = isset($entity->id) ? $entity->id : 0;
     $slug = $this->createSLug(strtolower(Inflector::slug($value, $config['replacement'])), 0, $id);
     $entity->set($config['slug'], $slug);
 }
开发者ID:Jurrieb,项目名称:lifespark,代码行数:8,代码来源:SluggableBehavior.php

示例14: transform

 /**
  * Creates a set of files from the initial data and returns them as key/value
  * pairs, where the path on disk maps to name which each file should have.
  * The file name will be sluggified (using Inflector::slug()) and lowercased.
  *
  * Example:
  *
  * ```
  *   [
  *     '/tmp/path/to/file/on/disk' => 'file.pdf',
  *     '/tmp/path/to/file/on/disk-2' => 'file-preview.png',
  *   ]
  * ```
  *
  * @return array key/value pairs of temp files mapping to their names
  */
 public function transform()
 {
     $filename = pathinfo($this->data['name'], PATHINFO_FILENAME);
     $filename = Inflector::slug($filename, '-');
     $ext = pathinfo($this->data['name'], PATHINFO_EXTENSION);
     if (!empty($ext)) {
         $filename = $filename . '.' . $ext;
     }
     return [$this->data['tmp_name'] => strtolower($filename)];
 }
开发者ID:jxav,项目名称:cakephp-upload,代码行数:26,代码来源:SlugTransformer.php

示例15: tab

 public function tab()
 {
     $tab = array_shift($this->_tabs);
     $class = 'tab ' . strtolower(Inflector::slug($tab));
     if (!$this->_isActivated) {
         $this->_isActivated = true;
         $class .= ' active';
     }
     return $class;
 }
开发者ID:Aerue,项目名称:avalia,代码行数:10,代码来源:BetterTabHelper.php


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