CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.2 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.2
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbAclSchema
  • DbConfigTask
  • DboAdodb
  • DboDb2
  • DboFirebird
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOdbc
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • DboSybase
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • Flay
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • i18nSchema
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JsHelper
  • JsHelperObject
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginTask
  • ProjectTask
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • SessionsSchema
  • Set
  • Shell
  • String
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • __enclose
  • make_clean_css
  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  • write_css_cache
  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * Pluralize and singularize English words.
  5:  *
  6:  * Used by Cake's naming conventions throughout the framework.
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs
 20:  * @since         CakePHP(tm) v 0.2.9
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Included libraries.
 28:  *
 29:  */
 30: if (!class_exists('Object')) {
 31:     uses('object');
 32: }
 33: if (!class_exists('Set')) {
 34:     require LIBS . 'set.php';
 35: }
 36: /**
 37:  * Pluralize and singularize English words.
 38:  *
 39:  * Inflector pluralizes and singularizes English nouns.
 40:  * Used by Cake's naming conventions throughout the framework.
 41:  * Test with $i = new Inflector(); $i->test();
 42:  *
 43:  * @package       cake
 44:  * @subpackage    cake.cake.libs
 45:  * @link          http://book.cakephp.org/view/491/Inflector
 46:  */
 47: class Inflector extends Object {
 48: /**
 49:  * Pluralized words.
 50:  *
 51:  * @var array
 52:  * @access private
 53:  **/
 54:     var $pluralized = array();
 55: /**
 56:  * List of pluralization rules in the form of pattern => replacement.
 57:  *
 58:  * @var array
 59:  * @access public
 60:  * @link http://book.cakephp.org/view/47/Custom-Inflections
 61:  **/
 62:     var $pluralRules = array();
 63: /**
 64:  * Singularized words.
 65:  *
 66:  * @var array
 67:  * @access private
 68:  **/
 69:     var $singularized = array();
 70: /**
 71:  * List of singularization rules in the form of pattern => replacement.
 72:  *
 73:  * @var array
 74:  * @access public
 75:  * @link http://book.cakephp.org/view/47/Custom-Inflections
 76:  **/
 77:     var $singularRules = array();
 78: /**
 79:  * Plural rules from inflections.php
 80:  *
 81:  * @var array
 82:  * @access private
 83:  **/
 84:     var $__pluralRules = array();
 85: /**
 86:  * Un-inflected plural rules from inflections.php
 87:  *
 88:  * @var array
 89:  * @access private
 90:  **/
 91:     var $__uninflectedPlural = array();
 92: /**
 93:  * Irregular plural rules from inflections.php
 94:  *
 95:  * @var array
 96:  * @access private
 97:  **/
 98:     var $__irregularPlural = array();
 99: /**
100:  * Singular rules from inflections.php
101:  *
102:  * @var array
103:  * @access private
104:  **/
105:     var $__singularRules = array();
106: /**
107:  * Un-inflectd singular rules from inflections.php
108:  *
109:  * @var array
110:  * @access private
111:  **/
112:     var $__uninflectedSingular = array();
113: /**
114:  * Irregular singular rules from inflections.php
115:  *
116:  * @var array
117:  * @access private
118:  **/
119:     var $__irregularSingular = array();
120: /**
121:  * Gets a reference to the Inflector object instance
122:  *
123:  * @return object
124:  * @access public
125:  */
126:     function &getInstance() {
127:         static $instance = array();
128: 
129:         if (!$instance) {
130:             $instance[0] =& new Inflector();
131:             if (file_exists(CONFIGS.'inflections.php')) {
132:                 include(CONFIGS.'inflections.php');
133:                 $instance[0]->__pluralRules = $pluralRules;
134:                 $instance[0]->__uninflectedPlural = $uninflectedPlural;
135:                 $instance[0]->__irregularPlural = $irregularPlural;
136:                 $instance[0]->__singularRules = $singularRules;
137:                 $instance[0]->__uninflectedSingular = $uninflectedPlural;
138:                 $instance[0]->__irregularSingular = array_flip($irregularPlural);
139:             }
140:         }
141:         return $instance[0];
142:     }
143: /**
144:  * Initializes plural inflection rules.
145:  *
146:  * @return void
147:  * @access private
148:  */
149:     function __initPluralRules() {
150:         $corePluralRules = array(
151:             '/(s)tatus$/i' => '\1\2tatuses',
152:             '/(quiz)$/i' => '\1zes',
153:             '/^(ox)$/i' => '\1\2en',
154:             '/([m|l])ouse$/i' => '\1ice',
155:             '/(matr|vert|ind)(ix|ex)$/i'  => '\1ices',
156:             '/(x|ch|ss|sh)$/i' => '\1es',
157:             '/([^aeiouy]|qu)y$/i' => '\1ies',
158:             '/(hive)$/i' => '\1s',
159:             '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
160:             '/sis$/i' => 'ses',
161:             '/([ti])um$/i' => '\1a',
162:             '/(p)erson$/i' => '\1eople',
163:             '/(m)an$/i' => '\1en',
164:             '/(c)hild$/i' => '\1hildren',
165:             '/(buffal|tomat)o$/i' => '\1\2oes',
166:             '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i',
167:             '/us$/' => 'uses',
168:             '/(alias)$/i' => '\1es',
169:             '/(ax|cris|test)is$/i' => '\1es',
170:             '/s$/' => 's',
171:             '/^$/' => '',
172:             '/$/' => 's');
173: 
174:         $coreUninflectedPlural = array(
175:             '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'Amoyese',
176:             'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
177:             'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
178:             'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
179:             'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese',
180:             'Kongoese', 'Lucchese', 'mackerel', 'Maltese', 'media', 'mews', 'moose', 'mumps', 'Nankingese', 'news',
181:             'nexus', 'Niasese', 'Pekingese', 'People', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings',
182:             'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears',
183:             'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese',
184:             'whiting', 'wildebeest', 'Yengeese');
185: 
186:         $coreIrregularPlural = array(
187:             'atlas' => 'atlases',
188:             'beef' => 'beefs',
189:             'brother' => 'brothers',
190:             'child' => 'children',
191:             'corpus' => 'corpuses',
192:             'cow' => 'cows',
193:             'ganglion' => 'ganglions',
194:             'genie' => 'genies',
195:             'genus' => 'genera',
196:             'graffito' => 'graffiti',
197:             'hoof' => 'hoofs',
198:             'loaf' => 'loaves',
199:             'man' => 'men',
200:             'money' => 'monies',
201:             'mongoose' => 'mongooses',
202:             'move' => 'moves',
203:             'mythos' => 'mythoi',
204:             'numen' => 'numina',
205:             'occiput' => 'occiputs',
206:             'octopus' => 'octopuses',
207:             'opus' => 'opuses',
208:             'ox' => 'oxen',
209:             'penis' => 'penises',
210:             'person' => 'people',
211:             'sex' => 'sexes',
212:             'soliloquy' => 'soliloquies',
213:             'testis' => 'testes',
214:             'trilby' => 'trilbys',
215:             'turf' => 'turfs');
216: 
217:         $pluralRules = Set::pushDiff($this->__pluralRules, $corePluralRules);
218:         $uninflected = Set::pushDiff($this->__uninflectedPlural, $coreUninflectedPlural);
219:         $irregular = Set::pushDiff($this->__irregularPlural, $coreIrregularPlural);
220: 
221:         $this->pluralRules = array('pluralRules' => $pluralRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
222:         $this->pluralized = array();
223:     }
224: /**
225:  * Return $word in plural form.
226:  *
227:  * @param string $word Word in singular
228:  * @return string Word in plural
229:  * @access public
230:  * @static
231:  * @link http://book.cakephp.org/view/572/Class-methods
232:  */
233:     function pluralize($word) {
234:         $_this =& Inflector::getInstance();
235:         if (!isset($_this->pluralRules) || empty($_this->pluralRules)) {
236:             $_this->__initPluralRules();
237:         }
238: 
239:         if (isset($_this->pluralized[$word])) {
240:             return $_this->pluralized[$word];
241:         }
242:         extract($_this->pluralRules);
243: 
244:         if (!isset($regexUninflected) || !isset($regexIrregular)) {
245:             $regexUninflected = __enclose(implode( '|', $uninflected));
246:             $regexIrregular = __enclose(implode( '|', array_keys($irregular)));
247:             $_this->pluralRules['regexUninflected'] = $regexUninflected;
248:             $_this->pluralRules['regexIrregular'] = $regexIrregular;
249:         }
250: 
251:         if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) {
252:             $_this->pluralized[$word] = $word;
253:             return $word;
254:         }
255: 
256:         if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
257:             $_this->pluralized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1);
258:             return $_this->pluralized[$word];
259:         }
260: 
261:         foreach ($pluralRules as $rule => $replacement) {
262:             if (preg_match($rule, $word)) {
263:                 $_this->pluralized[$word] = preg_replace($rule, $replacement, $word);
264:                 return $_this->pluralized[$word];
265:             }
266:         }
267:     }
268: /**
269:  * Initializes singular inflection rules.
270:  *
271:  * @return void
272:  * @access protected
273:  */
274:     function __initSingularRules() {
275:         $coreSingularRules = array(
276:             '/(s)tatuses$/i' => '\1\2tatus',
277:             '/^(.*)(menu)s$/i' => '\1\2',
278:             '/(quiz)zes$/i' => '\\1',
279:             '/(matr)ices$/i' => '\1ix',
280:             '/(vert|ind)ices$/i' => '\1ex',
281:             '/^(ox)en/i' => '\1',
282:             '/(alias)(es)*$/i' => '\1',
283:             '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us',
284:             '/([ftw]ax)es/' => '\1',
285:             '/(cris|ax|test)es$/i' => '\1is',
286:             '/(shoe)s$/i' => '\1',
287:             '/(o)es$/i' => '\1',
288:             '/ouses$/' => 'ouse',
289:             '/uses$/' => 'us',
290:             '/([m|l])ice$/i' => '\1ouse',
291:             '/(x|ch|ss|sh)es$/i' => '\1',
292:             '/(m)ovies$/i' => '\1\2ovie',
293:             '/(s)eries$/i' => '\1\2eries',
294:             '/([^aeiouy]|qu)ies$/i' => '\1y',
295:             '/([lr])ves$/i' => '\1f',
296:             '/(tive)s$/i' => '\1',
297:             '/(hive)s$/i' => '\1',
298:             '/(drive)s$/i' => '\1',
299:             '/([^fo])ves$/i' => '\1fe',
300:             '/(^analy)ses$/i' => '\1sis',
301:             '/(analy|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
302:             '/([ti])a$/i' => '\1um',
303:             '/(p)eople$/i' => '\1\2erson',
304:             '/(m)en$/i' => '\1an',
305:             '/(c)hildren$/i' => '\1\2hild',
306:             '/(n)ews$/i' => '\1\2ews',
307:             '/eaus$/' => 'eau',
308:             '/^(.*us)$/' => '\\1',
309:             '/s$/i' => '');
310: 
311:         $coreUninflectedSingular = array(
312:             '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'Amoyese',
313:             'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
314:             'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
315:             'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
316:             'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese',
317:             'Kongoese', 'Lucchese', 'mackerel', 'Maltese', 'media', 'mews', 'moose', 'mumps', 'Nankingese', 'news',
318:             'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings',
319:             'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears',
320:             'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese',
321:             'whiting', 'wildebeest', 'Yengeese'
322:         );
323: 
324:         $coreIrregularSingular = array(
325:             'atlases' => 'atlas',
326:             'beefs' => 'beef',
327:             'brothers' => 'brother',
328:             'children' => 'child',
329:             'corpuses' => 'corpus',
330:             'cows' => 'cow',
331:             'ganglions' => 'ganglion',
332:             'genies' => 'genie',
333:             'genera' => 'genus',
334:             'graffiti' => 'graffito',
335:             'hoofs' => 'hoof',
336:             'loaves' => 'loaf',
337:             'men' => 'man',
338:             'monies' => 'money',
339:             'mongooses' => 'mongoose',
340:             'moves' => 'move',
341:             'mythoi' => 'mythos',
342:             'numina' => 'numen',
343:             'occiputs' => 'occiput',
344:             'octopuses' => 'octopus',
345:             'opuses' => 'opus',
346:             'oxen' => 'ox',
347:             'penises' => 'penis',
348:             'people' => 'person',
349:             'sexes' => 'sex',
350:             'soliloquies' => 'soliloquy',
351:             'testes' => 'testis',
352:             'trilbys' => 'trilby',
353:             'turfs' => 'turf',
354:             'waves' => 'wave'
355:         );
356: 
357:         $singularRules = Set::pushDiff($this->__singularRules, $coreSingularRules);
358:         $uninflected = Set::pushDiff($this->__uninflectedSingular, $coreUninflectedSingular);
359:         $irregular = Set::pushDiff($this->__irregularSingular, $coreIrregularSingular);
360: 
361:         $this->singularRules = array('singularRules' => $singularRules, 'uninflected' => $uninflected, 'irregular' => $irregular);
362:         $this->singularized = array();
363:     }
364: /**
365:  * Return $word in singular form.
366:  *
367:  * @param string $word Word in plural
368:  * @return string Word in singular
369:  * @access public
370:  * @static
371:  * @link http://book.cakephp.org/view/572/Class-methods
372:  */
373:     function singularize($word) {
374:         $_this =& Inflector::getInstance();
375:         if (!isset($_this->singularRules) || empty($_this->singularRules)) {
376:             $_this->__initSingularRules();
377:         }
378: 
379:         if (isset($_this->singularized[$word])) {
380:             return $_this->singularized[$word];
381:         }
382:         extract($_this->singularRules);
383: 
384:         if (!isset($regexUninflected) || !isset($regexIrregular)) {
385:             $regexUninflected = __enclose(implode( '|', $uninflected));
386:             $regexIrregular = __enclose(implode( '|', array_keys($irregular)));
387:             $_this->singularRules['regexUninflected'] = $regexUninflected;
388:             $_this->singularRules['regexIrregular'] = $regexIrregular;
389:         }
390: 
391:         if (preg_match('/^(' . $regexUninflected . ')$/i', $word, $regs)) {
392:             $_this->singularized[$word] = $word;
393:             return $word;
394:         }
395: 
396:         if (preg_match('/(.*)\\b(' . $regexIrregular . ')$/i', $word, $regs)) {
397:             $_this->singularized[$word] = $regs[1] . substr($word, 0, 1) . substr($irregular[strtolower($regs[2])], 1);
398:             return $_this->singularized[$word];
399:         }
400: 
401:         foreach ($singularRules as $rule => $replacement) {
402:             if (preg_match($rule, $word)) {
403:                 $_this->singularized[$word] = preg_replace($rule, $replacement, $word);
404:                 return $_this->singularized[$word];
405:             }
406:         }
407:         $_this->singularized[$word] = $word;
408:         return $word;
409:     }
410: /**
411:  * Returns the given lower_case_and_underscored_word as a CamelCased word.
412:  *
413:  * @param string $lower_case_and_underscored_word Word to camelize
414:  * @return string Camelized word. LikeThis.
415:  * @access public
416:  * @static
417:  * @link http://book.cakephp.org/view/572/Class-methods
418:  */
419:     function camelize($lowerCaseAndUnderscoredWord) {
420:         return str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
421:     }
422: /**
423:  * Returns the given camelCasedWord as an underscored_word.
424:  *
425:  * @param string $camelCasedWord Camel-cased word to be "underscorized"
426:  * @return string Underscore-syntaxed version of the $camelCasedWord
427:  * @access public
428:  * @static
429:  * @link http://book.cakephp.org/view/572/Class-methods
430:  */
431:     function underscore($camelCasedWord) {
432:         return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
433:     }
434: /**
435:  * Returns the given underscored_word_group as a Human Readable Word Group.
436:  * (Underscores are replaced by spaces and capitalized following words.)
437:  *
438:  * @param string $lower_case_and_underscored_word String to be made more readable
439:  * @return string Human-readable string
440:  * @access public
441:  * @static
442:  * @link http://book.cakephp.org/view/572/Class-methods
443:  */
444:     function humanize($lowerCaseAndUnderscoredWord) {
445:         return ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord));
446:     }
447: /**
448:  * Returns corresponding table name for given model $className. ("people" for the model class "Person").
449:  *
450:  * @param string $className Name of class to get database table name for
451:  * @return string Name of the database table for given class
452:  * @access public
453:  * @static
454:  * @link http://book.cakephp.org/view/572/Class-methods
455:  */
456:     function tableize($className) {
457:         return Inflector::pluralize(Inflector::underscore($className));
458:     }
459: /**
460:  * Returns Cake model class name ("Person" for the database table "people".) for given database table.
461:  *
462:  * @param string $tableName Name of database table to get class name for
463:  * @return string Class name
464:  * @access public
465:  * @static
466:  * @link http://book.cakephp.org/view/572/Class-methods
467:  */
468:     function classify($tableName) {
469:         return Inflector::camelize(Inflector::singularize($tableName));
470:     }
471: /**
472:  * Returns camelBacked version of an underscored string.
473:  *
474:  * @param string $string
475:  * @return string in variable form
476:  * @access public
477:  * @static
478:  * @link http://book.cakephp.org/view/572/Class-methods
479:  */
480:     function variable($string) {
481:         $string = Inflector::camelize(Inflector::underscore($string));
482:         $replace = strtolower(substr($string, 0, 1));
483:         return $replace . substr($string, 1);
484:     }
485: /**
486:  * Returns a string with all spaces converted to underscores (by default), accented
487:  * characters converted to non-accented characters, and non word characters removed.
488:  *
489:  * @param string $string
490:  * @param string $replacement
491:  * @return string
492:  * @access public
493:  * @static
494:  * @link http://book.cakephp.org/view/572/Class-methods
495:  */
496:     function slug($string, $replacement = '_') {
497:         if (!class_exists('String')) {
498:             require LIBS . 'string.php';
499:         }
500:         $map = array(
501:             '/à|á|å|â/' => 'a',
502:             '/è|é|ê|ẽ|ë/' => 'e',
503:             '/ì|í|î/' => 'i',
504:             '/ò|ó|ô|ø/' => 'o',
505:             '/ù|ú|ů|û/' => 'u',
506:             '/ç/' => 'c',
507:             '/ñ/' => 'n',
508:             '/ä|æ/' => 'ae',
509:             '/ö/' => 'oe',
510:             '/ü/' => 'ue',
511:             '/Ä/' => 'Ae',
512:             '/Ü/' => 'Ue',
513:             '/Ö/' => 'Oe',
514:             '/ß/' => 'ss',
515:             '/[^\w\s]/' => ' ',
516:             '/\\s+/' => $replacement,
517:             String::insert('/^[:replacement]+|[:replacement]+$/', array('replacement' => preg_quote($replacement, '/'))) => '',
518:         );
519:         return preg_replace(array_keys($map), array_values($map), $string);
520:     }
521: }
522: /**
523:  * Enclose a string for preg matching.
524:  *
525:  * @param string $string String to enclose
526:  * @return string Enclosed string
527:  */
528:     function __enclose($string) {
529:         return '(?:' . $string . ')';
530:     }
531: ?>
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs