Cakephp 3 mysql column zerofill not working


#1

– table –

`indice` INT(2) UNSIGNED ZEROFILL NOT NULL` 

– Controller –

    $this->loadModel('Chapters');
    $lastChapter = $this->Chapters->find()
    ->where([
        'Chapters.materials_id' => $material->id,
    ])
    ->order([
        'Chapters.indice' => 'DESC'
    ])
    ->limit(1)
    ->first();

    debug($lastChapter);

– RESULT –

object(App\Model\Entity\Chapter) {

	'id' => (int) 59,
	'nome' => 'Divisão',
	'descricao' => 'Divisão',
	'color' => 'azul',
	'indice' => (int) 6,
	'materials_id' => (int) 3,
	'created_at' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-07T07:06:50+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'updated_at' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-06-04T22:08:50+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'sequencia' => (int) 6,
	'[new]' => false,
	'[accessible]' => [
		'nome' => true,
		'descricao' => true,
		'color' => true,
		'indice' => true,
		'materials_id' => true,
		'created_at' => true,
		'updated_at' => true,
		'sequencia' => true,
		'material' => true
	],
	'[dirty]' => [],
	'[original]' => [],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'Chapters'

}

#2

Zerofill only works for clients, PHP and other clients receive the int without zerofill

You should use str_pad to do the zerofill in the template