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.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • Form
  • Schema
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Form;
 16: 
 17: /**
 18:  * Contains the schema information for Form instances.
 19:  */
 20: class Schema
 21: {
 22:     /**
 23:      * The fields in this schema.
 24:      *
 25:      * @var array
 26:      */
 27:     protected $_fields = [];
 28: 
 29:     /**
 30:      * The default values for fields.
 31:      *
 32:      * @var array
 33:      */
 34:     protected $_fieldDefaults = [
 35:         'type' => null,
 36:         'length' => null,
 37:         'precision' => null,
 38:         'default' => null,
 39:     ];
 40: 
 41:     /**
 42:      * Add multiple fields to the schema.
 43:      *
 44:      * @param array $fields The fields to add.
 45:      * @return $this
 46:      */
 47:     public function addFields(array $fields)
 48:     {
 49:         foreach ($fields as $name => $attrs) {
 50:             $this->addField($name, $attrs);
 51:         }
 52: 
 53:         return $this;
 54:     }
 55: 
 56:     /**
 57:      * Adds a field to the schema.
 58:      *
 59:      * @param string $name The field name.
 60:      * @param string|array $attrs The attributes for the field, or the type
 61:      *   as a string.
 62:      * @return $this
 63:      */
 64:     public function addField($name, $attrs)
 65:     {
 66:         if (is_string($attrs)) {
 67:             $attrs = ['type' => $attrs];
 68:         }
 69:         $attrs = array_intersect_key($attrs, $this->_fieldDefaults);
 70:         $this->_fields[$name] = $attrs + $this->_fieldDefaults;
 71: 
 72:         return $this;
 73:     }
 74: 
 75:     /**
 76:      * Removes a field to the schema.
 77:      *
 78:      * @param string $name The field to remove.
 79:      * @return $this
 80:      */
 81:     public function removeField($name)
 82:     {
 83:         unset($this->_fields[$name]);
 84: 
 85:         return $this;
 86:     }
 87: 
 88:     /**
 89:      * Get the list of fields in the schema.
 90:      *
 91:      * @return string[] The list of field names.
 92:      */
 93:     public function fields()
 94:     {
 95:         return array_keys($this->_fields);
 96:     }
 97: 
 98:     /**
 99:      * Get the attributes for a given field.
100:      *
101:      * @param string $name The field name.
102:      * @return array|null The attributes for a field, or null.
103:      */
104:     public function field($name)
105:     {
106:         if (!isset($this->_fields[$name])) {
107:             return null;
108:         }
109: 
110:         return $this->_fields[$name];
111:     }
112: 
113:     /**
114:      * Get the type of the named field.
115:      *
116:      * @param string $name The name of the field.
117:      * @return string|null Either the field type or null if the
118:      *   field does not exist.
119:      */
120:     public function fieldType($name)
121:     {
122:         $field = $this->field($name);
123:         if (!$field) {
124:             return null;
125:         }
126: 
127:         return $field['type'];
128:     }
129: 
130:     /**
131:      * Get the printable version of this object
132:      *
133:      * @return array
134:      */
135:     public function __debugInfo()
136:     {
137:         return [
138:             '_fields' => $this->_fields
139:         ];
140:     }
141: }
142: 
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