Cake\ORM\Table::__construct PHP Method

__construct() public method

The $config array understands the following keys: - table: Name of the database table to represent - alias: Alias to be assigned to this table (default to table name) - connection: The connection instance to use - entityClass: The fully namespaced class name of the entity class that will represent rows in this table. - schema: A \Cake\Database\Schema\Table object or an array that can be passed to it. - eventManager: An instance of an event manager to use for internal events - behaviors: A BehaviorRegistry. Generally not used outside of tests. - associations: An AssociationCollection instance. - validator: A Validator instance which is assigned as the "default" validation set, or an associative array, where key is the name of the validation set and value the Validator instance.
public __construct ( array $config = [] )
$config array List of options for this table
    public function __construct(array $config = [])
    {
        if (!empty($config['registryAlias'])) {
            $this->registryAlias($config['registryAlias']);
        }
        if (!empty($config['table'])) {
            $this->table($config['table']);
        }
        if (!empty($config['alias'])) {
            $this->alias($config['alias']);
        }
        if (!empty($config['connection'])) {
            $this->connection($config['connection']);
        }
        if (!empty($config['schema'])) {
            $this->schema($config['schema']);
        }
        if (!empty($config['entityClass'])) {
            $this->entityClass($config['entityClass']);
        }
        $eventManager = $behaviors = $associations = null;
        if (!empty($config['eventManager'])) {
            $eventManager = $config['eventManager'];
        }
        if (!empty($config['behaviors'])) {
            $behaviors = $config['behaviors'];
        }
        if (!empty($config['associations'])) {
            $associations = $config['associations'];
        }
        if (!empty($config['validator'])) {
            if (!is_array($config['validator'])) {
                $this->validator(static::DEFAULT_VALIDATOR, $config['validator']);
            } else {
                foreach ($config['validator'] as $name => $validator) {
                    $this->validator($name, $validator);
                }
            }
        }
        $this->_eventManager = $eventManager ?: new EventManager();
        $this->_behaviors = $behaviors ?: new BehaviorRegistry();
        $this->_behaviors->setTable($this);
        $this->_associations = $associations ?: new AssociationCollection();
        $this->initialize($config);
        $this->_eventManager->on($this);
        $this->dispatchEvent('Model.initialize');
    }

Usage Example

 public function __construct($id = false, $table = null, $ds = null)
 {
     parent::__construct($id, $table, $ds);
     $this->filterTimes = array('all_time' => array('label' => 'All Time', 'limit' => null, 'group' => "DATE_FORMAT(Incidents.created, '%m %Y')"), 'day' => array('label' => 'Last Day', 'limit' => date('Y-m-d', strtotime('-1 day')), 'group' => "DATE_FORMAT(Incidents.created, '%a %b %d %Y %H')"), 'week' => array('label' => 'Last Week', 'limit' => date('Y-m-d', strtotime('-1 week')), 'group' => "DATE_FORMAT(Incidents.created, '%a %b %d %Y')"), 'month' => array('label' => 'Last Month', 'limit' => date('Y-m-d', strtotime('-1 month')), 'group' => "DATE_FORMAT(Incidents.created, '%a %b %d %Y')"), 'year' => array('label' => 'Last Year', 'limit' => date('Y-m-d', strtotime('-1 year')), 'group' => "DATE_FORMAT(Incidents.created, '%b %u %Y')"));
 }
All Usage Examples Of Cake\ORM\Table::__construct