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


PHP Table::exists方法代码示例

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


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

示例1: exists

 public function exists($conditions, $checkStatus = false)
 {
     if (!is_array($conditions) && is_numeric($conditions)) {
         $conditions = ['id' => $conditions];
     }
     if ($checkStatus && !empty($this->_activeStatuses)) {
         $conditions['status IN '] = $this->_activeStatuses;
     }
     return parent::exists($conditions);
 }
开发者ID:BreakfastMonkey,项目名称:breakfast-combo,代码行数:10,代码来源:Table.php

示例2: existsById

 /**
  * 2.x shim for exists() and primary key.
  *
  * @param int $id
  * @return bool
  */
 public function existsById($id)
 {
     $conditions = [$this->primaryKey() => $id];
     return parent::exists($conditions);
 }
开发者ID:dereuromark,项目名称:cakephp-shim,代码行数:11,代码来源:Table.php

示例3: generateSlug

 /**
  * Slug method
  *
  * For the given string, generate a slug. The replacements used are based on the mode setting, If tidy is false
  * (only possible if directly called - primarily for tracing and testing) separators will not be cleaned up
  * and so slugs like "-----as---df-----" are possible, which by default would otherwise be returned as "as-df".
  * If the mode is "id" and the first charcter of the regex-ed slug is numeric, it will be prefixed with an x.
  * If unique is set to true, check for a unique slug and if unavailable suffix the slug with -1, -2, -3 etc.
  * until a unique slug is found
  *
  * @param string $value
  * @param \Cake\ORM\Entity|null $entity
  * @return string A slug
  */
 public function generateSlug($value, Entity $entity = null)
 {
     $separator = $this->_config['separator'];
     $string = str_replace(["\r\n", "\r", "\n"], ' ', $value);
     $replace = $this->_config['replace'];
     if ($replace) {
         $string = str_replace(array_keys($replace), array_values($replace), $string);
     }
     if ($this->_config['mode'] === 'ascii') {
         $slug = Inflector::slug($string, $separator);
     } else {
         $regex = $this->_regex($this->_config['mode']);
         if ($regex) {
             $slug = $this->_pregReplace('@[' . $regex . ']@Su', $separator, $string);
         } else {
             $slug = $string;
         }
     }
     if ($this->_config['tidy']) {
         $slug = $this->_pregReplace('/' . $separator . '+/', $separator, $slug);
         $slug = trim($slug, $separator);
         if ($slug && $this->_config['mode'] === 'id' && is_numeric($slug[0])) {
             $slug = 'x' . $slug;
         }
     }
     if ($this->_config['length'] && mb_strlen($slug) > $this->_config['length']) {
         $slug = mb_substr($slug, 0, $this->_config['length']);
     }
     if ($this->_config['case']) {
         $case = $this->_config['case'];
         if ($case === 'up') {
             $slug = mb_strtoupper($slug);
         } else {
             $slug = mb_strtolower($slug);
         }
         if (in_array($case, ['title', 'camel'])) {
             $words = explode($separator, $slug);
             foreach ($words as $i => &$word) {
                 $firstChar = mb_substr($word, 0, 1);
                 $rest = mb_substr($word, 1, mb_strlen($word) - 1);
                 $firstCharUp = mb_strtoupper($firstChar);
                 $word = $firstCharUp . $rest;
             }
             if ($case === 'title') {
                 $slug = implode($words, $separator);
             } elseif ($case === 'camel') {
                 $slug = implode($words);
             }
         }
     }
     if ($this->_config['unique']) {
         if (!$entity) {
             throw new Exception('Needs an Entity to work on');
         }
         $field = $this->_table->alias() . '.' . $this->_config['field'];
         $conditions = [$field => $slug];
         $conditions = array_merge($conditions, $this->_config['scope']);
         $id = $entity->get($this->_table->primaryKey());
         if ($id) {
             $conditions['NOT'][$this->_table->alias() . '.' . $this->_table->primaryKey()] = $id;
         }
         $i = 0;
         $suffix = '';
         while ($this->_table->exists($conditions)) {
             $i++;
             $suffix = $separator . $i;
             if ($this->_config['length'] && mb_strlen($slug . $suffix) > $this->_config['length']) {
                 $slug = mb_substr($slug, 0, $this->_config['length'] - mb_strlen($suffix));
             }
             $conditions[$field] = $slug . $suffix;
         }
         if ($suffix) {
             $slug .= $suffix;
         }
     }
     return $slug;
 }
开发者ID:dereuromark,项目名称:cakephp-tools,代码行数:91,代码来源:SluggedBehavior.php


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