CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.3 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.3
      • 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

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
      • Session
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Constraint
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • BreadcrumbsHelper
  • FlashHelper
  • FormHelper
  • HtmlHelper
  • NumberHelper
  • PaginatorHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper
  • UrlHelper

Traits

  • IdGeneratorTrait
  • SecureFieldTokenTrait
 1: <?php
 2: /**
 3:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 4:  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 5:  *
 6:  * Licensed under The MIT License
 7:  * For full copyright and license information, please see the LICENSE.txt
 8:  * Redistributions of files must retain the above copyright notice.
 9:  *
10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11:  * @link          http://cakephp.org CakePHP(tm) Project
12:  * @since         3.0.0
13:  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
14:  */
15: namespace Cake\View\Helper;
16: 
17: use Cake\Utility\Inflector;
18: 
19: /**
20:  * A trait that provides id generating methods to be
21:  * used in various widget classes.
22:  */
23: trait IdGeneratorTrait
24: {
25: 
26:     /**
27:      * Prefix for id attribute.
28:      *
29:      * @var string
30:      */
31:     protected $_idPrefix = null;
32: 
33:     /**
34:      * A list of id suffixes used in the current rendering.
35:      *
36:      * @var array
37:      */
38:     protected $_idSuffixes = [];
39: 
40:     /**
41:      * Clear the stored ID suffixes.
42:      *
43:      * @return void
44:      */
45:     protected function _clearIds()
46:     {
47:         $this->_idSuffixes = [];
48:     }
49: 
50:     /**
51:      * Generate an ID attribute for an element.
52:      *
53:      * Ensures that id's for a given set of fields are unique.
54:      *
55:      * @param string $name The ID attribute name.
56:      * @param string $val The ID attribute value.
57:      * @return string Generated id.
58:      */
59:     protected function _id($name, $val)
60:     {
61:         $name = $this->_domId($name);
62: 
63:         $idSuffix = mb_strtolower(str_replace(['/', '@', '<', '>', ' ', '"', '\''], '-', $val));
64:         $count = 1;
65:         $check = $idSuffix;
66:         while (in_array($check, $this->_idSuffixes)) {
67:             $check = $idSuffix . $count++;
68:         }
69:         $this->_idSuffixes[] = $check;
70: 
71:         return trim($name . '-' . $check, '-');
72:     }
73: 
74:     /**
75:      * Generate an ID suitable for use in an ID attribute.
76:      *
77:      * @param string $value The value to convert into an ID.
78:      * @return string The generated id.
79:      */
80:     protected function _domId($value)
81:     {
82:         $domId = mb_strtolower(Inflector::slug($value, '-'));
83:         if (!empty($this->_idPrefix)) {
84:             $domId = $this->_idPrefix . '-' . $domId;
85:         }
86: 
87:         return $domId;
88:     }
89: }
90: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs