Skip to content

Instantly share code, notes, and snippets.

@fullybaked
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fullybaked/543f05aae3e12c3f5c95 to your computer and use it in GitHub Desktop.
Save fullybaked/543f05aae3e12c3f5c95 to your computer and use it in GitHub Desktop.
Cakephp date format issue
// open athens dates come from a date picker text input in the view, in the format dd-mm-yyyy
<?= $this->Form->input('openathens_start_date, [
'type' => 'text',
'class' => 'datepicker']);?>
<?= $this->Form->input('openathens_end_date, [
'type' => 'text',
'class' => 'datepicker']);?>
// in the Table
public function beforeMarshal(Event $event, \ArrayObject $data, \ArrayObject $options)
{
if (isset($data['openathens_start_date'])) {
$data['openathens_start_date'] = new Time($data['openathens_start_date']);
}
if (isset($data['openathens_end_date'])) {
$data['openathens_end_date'] = new Time($data['openathens_end_date']);
}
}
// in controller
$organisation = $this->Organisations->patchEntity($organisation, $this->request->data);
if ($this->Organisations->save($organisation)) {
$this->Flash->success('The organisation has been saved.');
return $this->redirect(['action' => 'index']);
}
// error
// Invalid datetime format: 1292 Incorrect date value: '11-08-2015' for column 'openathens_start_date' at row 1
@fullybaked
Copy link
Author

object(App\Model\Entity\Organisation) {

    'new' => true,
    'accessible' => [
        'name' => true,
        'short_name' => true,
        'type' => true,
        'admin_core_colour' => true,
        'on_trial' => true,
        'region' => true,
        'openathens_active' => true,
        'openathens_entity_id' => true,
        'openathens_start_date' => true,
        'openathens_end_date' => true,
        'updated_by' => true,
        'parent_crm_organisation' => true,
        'child_crm_organisations' => true
    ],
    'properties' => [
        'name' => 'Fully Baked',
        'short_name' => 'FLB',
        'type' => (int) 2,
        'region' => (int) 2,
        'openathens_active' => false,
        'openathens_start_date' => object(Cake\I18n\Time) {

            'time' => '2015-08-11T00:00:00+0000',
            'timezone' => 'UTC',
            'fixedNowTime' => false

        },
        'openathens_end_date' => object(Cake\I18n\Time) {

            'time' => '2015-08-11T00:00:00+0000',
            'timezone' => 'UTC',
            'fixedNowTime' => false

        }
    ],
    'dirty' => [
        'name' => true,
        'short_name' => true,
        'type' => true,
        'region' => true,
        'openathens_active' => true,
        'openathens_start_date' => true,
        'openathens_end_date' => true
    ],
    'original' => [],
    'virtual' => [],
    'errors' => [],
    'repository' => 'Organisations'

}

@fullybaked
Copy link
Author

object(Cake\Database\Schema\Table) {
    [protected] _table => 'organisations'
    [protected] _columns => [
        'id' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => '',
            'autoIncrement' => true,
            'precision' => null
        ],
        'name' => [
            'type' => 'string',
            'length' => (int) 255,
            'null' => false,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'short_name' => [
            'type' => 'string',
            'length' => (int) 255,
            'null' => false,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'type' => [
            'type' => 'integer',
            'length' => (int) 3,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'autoIncrement' => null
        ],
        'admin_core_colour' => [
            'type' => 'string',
            'length' => (int) 6,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'on_trial' => [
            'type' => 'boolean',
            'length' => null,
            'null' => false,
            'default' => '0',
            'comment' => '',
            'precision' => null
        ],
        'region' => [
            'type' => 'integer',
            'length' => (int) 3,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => 'id from crm_regions',
            'precision' => null,
            'autoIncrement' => null
        ],
        'map_region' => [
            'type' => 'integer',
            'length' => (int) 3,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => 'id from crm_map_regions',
            'precision' => null,
            'autoIncrement' => null
        ],
        'rip_main_contact' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => 'id from crm_contacts',
            'precision' => null,
            'autoIncrement' => null
        ],
        'ripfa_main_contact' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => 'id from crm_contacts',
            'precision' => null,
            'autoIncrement' => null
        ],
        'rip_account_manager' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => 'id from crm_contacts',
            'precision' => null,
            'autoIncrement' => null
        ],
        'ripfa_account_manager' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => 'id from crm_contacts',
            'precision' => null,
            'autoIncrement' => null
        ],
        'notify_email' => [
            'type' => 'string',
            'length' => (int) 84,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'from_email' => [
            'type' => 'string',
            'length' => (int) 84,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'reply_to_email' => [
            'type' => 'string',
            'length' => (int) 84,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'return_path_email' => [
            'type' => 'string',
            'length' => (int) 84,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'max_event_invites' => [
            'type' => 'integer',
            'length' => (int) 3,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'autoIncrement' => null
        ],
        'max_extra_rip_accs' => [
            'type' => 'integer',
            'length' => (int) 3,
            'unsigned' => true,
            'null' => false,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'autoIncrement' => null
        ],
        'header_logo' => [
            'type' => 'string',
            'length' => (int) 100,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'footer_logo' => [
            'type' => 'string',
            'length' => (int) 100,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'parent_id' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'autoIncrement' => null
        ],
        'openathens_active' => [
            'type' => 'boolean',
            'length' => null,
            'null' => false,
            'default' => '0',
            'comment' => '',
            'precision' => null
        ],
        'openathens_entity_id' => [
            'type' => 'string',
            'length' => (int) 255,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'fixed' => null
        ],
        'openathens_start_date' => [
            'type' => 'date',
            'length' => null,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null
        ],
        'openathens_end_date' => [
            'type' => 'date',
            'length' => null,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null
        ],
        'modified' => [
            'type' => 'timestamp',
            'length' => null,
            'null' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'comment' => '',
            'precision' => null
        ],
        'modified_by' => [
            'type' => 'integer',
            'length' => (int) 8,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => 'id from crm_users',
            'precision' => null,
            'autoIncrement' => null
        ],
        'created' => [
            'type' => 'timestamp',
            'length' => null,
            'null' => false,
            'default' => '0000-00-00 00:00:00',
            'comment' => '',
            'precision' => null
        ],
        'created_by' => [
            'type' => 'integer',
            'length' => (int) 11,
            'unsigned' => true,
            'null' => true,
            'default' => null,
            'comment' => '',
            'precision' => null,
            'autoIncrement' => null
        ]
    ]
    [protected] _indexes => []
    [protected] _constraints => [
        'primary' => [
            'type' => 'primary',
            'columns' => [
                (int) 0 => 'id'
            ],
            'length' => []
        ],
        'id' => [
            'type' => 'unique',
            'columns' => [
                (int) 0 => 'id'
            ],
            'length' => []
        ]
    ]
    [protected] _options => [
        'engine' => 'InnoDB',
        'collation' => 'utf8_general_ci'
    ]
    [protected] _temporary => false
    [protected] _columnKeys => [
        'type' => null,
        'length' => null,
        'precision' => null,
        'null' => null,
        'default' => null,
        'comment' => null
    ]
    [protected] _columnExtras => [
        'string' => [
            'fixed' => null
        ],
        'integer' => [
            'unsigned' => null,
            'autoIncrement' => null
        ],
        'biginteger' => [
            'unsigned' => null,
            'autoIncrement' => null
        ],
        'decimal' => [
            'unsigned' => null
        ],
        'float' => [
            'unsigned' => null
        ]
    ]
    [protected] _indexKeys => [
        'type' => null,
        'columns' => [],
        'length' => [],
        'references' => [],
        'update' => 'restrict',
        'delete' => 'restrict'
    ]
    [protected] _validIndexTypes => [
        (int) 0 => 'index',
        (int) 1 => 'fulltext'
    ]
    [protected] _validConstraintTypes => [
        (int) 0 => 'primary',
        (int) 1 => 'unique',
        (int) 2 => 'foreign'
    ]
    [protected] _validForeignKeyActions => [
        (int) 0 => 'cascade',
        (int) 1 => 'setNull',
        (int) 2 => 'setDefault',
        (int) 3 => 'noAction',
        (int) 4 => 'restrict'
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment