CRUDlex not working when add new table in yaml

129 Views Asked by At

i try to find a faster way to generate UI for existing database, CRUD, composer way, using symfony component.

found CRUDlex. Doing install with composer, also setup CRUDlex sample it works fine, until i m add new table definition in sample crud.yml

category:
  label: Category
  table: category
  fields:
    name:
      type: text
      label: Name
      required: true
      unique: true  

what ever table added in yml, it's always throw error similar to this when access http://localhost/crudlex/web/category

InvalidFieldNameException in AbstractMySQLDriver.php line 71: An exception occurred while executing 'SELECT COUNT(id) FROM `category` `category` WHERE deleted_at IS NULL':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'deleted_at' in 'where clause'

complete error message please check screenshot below CRUDlex Error

crudlex always asking "id" and 'deleted_at'

the code is same as CRUDled sample index.php

    $loader = require __DIR__.'/../vendor/autoload.php';

    //$loader->add('CRUDlex', __DIR__.'/../../CRUDlex/src');
    $app = new Silex\Application();

    $app['debug'] = true;

    $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
        'dbs.options' => array(
            'default' => array(
                'host'      => '127.0.0.1',
                'dbname'    => 'dbname',
                'user'      => 'root',
                'password'  => '',
                'charset'   => 'utf8',
            )
        ),
    ));
    $app->register(new Silex\Provider\SessionServiceProvider());

    $dataFactory = new CRUDlex\MySQLDataFactory($app['db']);
    $app->register(new CRUDlex\ServiceProvider(), array(
        'crud.file' => __DIR__ . '/../crud.yml',
        'crud.datafactory' => $dataFactory
    ));
    $app->register(new Silex\Provider\TwigServiceProvider());

    //$app['crud.layout'] = 'layout.twig';
    $app->mount('/', new CRUDlex\ControllerProvider());

    $app->match('/', function() use ($app) {
        return $app->redirect($app['url_generator']->generate('crudList', array('entity' => 'library')));
    })->bind('homepage');

    $app->run();

And folder structure

vendor
web
    > .htaccess
    > index.php
composer.json
crud.yml  

Note: I m totally new to silex and symfony2 component ^_^ Thank you, any suggest really appreciated

1

There are 1 best solutions below

2
On BEST ANSWER

you are missing (at least) one of the required meta fields:

  • created_at (datetime, not null): When the record was created
  • updated_at (datetime, not null): When the record was edited the last time
  • version (int, not null): The version of the record, increments with each edit
  • deleted_at (datetime): If not null: When the record was (soft-) deleted

The complete table creation SQL in your case would look like this:

CREATE TABLE `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `version` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;