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

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
 24:      * The fields in this schema.
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_fields = [];
 29: 
 30:     /**
 31:      * The default values for fields.
 32:      *
 33:      * @var array
 34:      */
 35:     protected $_fieldDefaults = [
 36:         'type' => null,
 37:         'length' => null,
 38:         'precision' => null,
 39:         'default' => null,
 40:     ];
 41: 
 42:     /**
 43:      * Add multiple fields to the schema.
 44:      *
 45:      * @param array $fields The fields to add.
 46:      * @return $this
 47:      */
 48:     public function addFields(array $fields)
 49:     {
 50:         foreach ($fields as $name => $attrs) {
 51:             $this->addField($name, $attrs);
 52:         }
 53: 
 54:         return $this;
 55:     }
 56: 
 57:     /**
 58:      * Adds a field to the schema.
 59:      *
 60:      * @param string $name The field name.
 61:      * @param string|array $attrs The attributes for the field, or the type
 62:      *   as a string.
 63:      * @return $this
 64:      */
 65:     public function addField($name, $attrs)
 66:     {
 67:         if (is_string($attrs)) {
 68:             $attrs = ['type' => $attrs];
 69:         }
 70:         $attrs = array_intersect_key($attrs, $this->_fieldDefaults);
 71:         $this->_fields[$name] = $attrs + $this->_fieldDefaults;
 72: 
 73:         return $this;
 74:     }
 75: 
 76:     /**
 77:      * Removes a field to the schema.
 78:      *
 79:      * @param string $name The field to remove.
 80:      * @return $this
 81:      */
 82:     public function removeField($name)
 83:     {
 84:         unset($this->_fields[$name]);
 85: 
 86:         return $this;
 87:     }
 88: 
 89:     /**
 90:      * Get the list of fields in the schema.
 91:      *
 92:      * @return string[] The list of field names.
 93:      */
 94:     public function fields()
 95:     {
 96:         return array_keys($this->_fields);
 97:     }
 98: 
 99:     /**
100:      * Get the attributes for a given field.
101:      *
102:      * @param string $name The field name.
103:      * @return null|array The attributes for a field, or null.
104:      */
105:     public function field($name)
106:     {
107:         if (!isset($this->_fields[$name])) {
108:             return null;
109:         }
110: 
111:         return $this->_fields[$name];
112:     }
113: 
114:     /**
115:      * Get the type of the named field.
116:      *
117:      * @param string $name The name of the field.
118:      * @return string|null Either the field type or null if the
119:      *   field does not exist.
120:      */
121:     public function fieldType($name)
122:     {
123:         $field = $this->field($name);
124:         if (!$field) {
125:             return null;
126:         }
127: 
128:         return $field['type'];
129:     }
130: 
131:     /**
132:      * Get the printable version of this object
133:      *
134:      * @return array
135:      */
136:     public function __debugInfo()
137:     {
138:         return [
139:             '_fields' => $this->_fields
140:         ];
141:     }
142: }
143: 
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