crud-view
crud-view copied to clipboard
Dates always zero
Hi,
I have a very basic app, based completely on the documentation. Here are the steps taken:
- Composer stuff:
composer self-update && composer create-project --prefer-dist cakephp/app
composer require friendsofcake/crud
composer require friendsofcake/crud-view
composer require friendsofcake/search
-
Put database credentials in
config/app.php. -
Cake stuff:
bin/cake plugin load Crud
bin/cake plugin load CrudView
bin/cake plugin load BootstrapUI
bin/cake plugin load Search
bin/cake plugin load Migrations
bin/cake bake migration CreateEntries title:string content:text created modified
bin/cake migrations migrate
- Create basic controller.
namespace App\Controller;
class CategoriesController extends AppController
{
// No code here, but we have all actions available to use!
}
This gives me a full-fledged entry admin on the /entries/ route. However, the dates (created and modified) always take on the value 0000-00-00 00:00:00.
If I alter the database to make dates use varchar(191) instead of datetime, I lose the calendar widget and validation on the front-end, but if I then put in a value like 2019-12-03 10:20:00, the value is stored properly.
I cannot figure out why this would happen. The formatting that is applied by the calendar widget looks different from what the database expects (like so: 12/03/2019 10:20 AM). However, when I inspect the input field, the value does appear to take on the form 2019-12-03 10:20:00, so that shouldn’t actually be a problem?
I can’t find anything in the logs, or in debug mode. I tried different locales and different database servers, but I get the same results.
This is what the migration produces:
use Migrations\AbstractMigration;
class CreateEntries extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
* @return void
*/
public function change()
{
$table = $this->table('entries');
$table->addColumn('title', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('content', 'text', [
'default' => null,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
}
As was pointed out by a colleague of mine, normally one would add $this->addBehavior('Timestamp'); to the model to fix this in Cake, but CrudView appears to omit models the way they’re usually defined.
Can you try an older version? maybe https://github.com/FriendsOfCake/crud-view/commit/991a198d708cc83477216e3dea38bcae2b904af2 caused issues
Will check that out. Thanks.
I tried with CrudView 0.12.0 (keeping the rest of the stack the same), and the problems persists.