在 yaml 中添加新 table 时 CRUDlex 不起作用

CRUDlex not working when add new table in yaml

我尝试使用 symfony 组件为现有数据库、CRUD、作曲家方式找到一种更快的生成 UI 的方法。

找到 CRUDlex. Doing install with composer, also setup CRUDlex sample 它工作正常,直到我在示例 crud.yml

中添加新的 table 定义
category:
  label: Category
  table: category
  fields:
    name:
      type: text
      label: Name
      required: true
      unique: true  

yml中添加的table什么的,访问的时候总是报类似这样的错误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'

完整的错误信息请查看下面的截图

crudlex 总是询问 "id" 和 'deleted_at'

代码与 CRUDled 示例相同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();

和文件夹结构

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

注意:我对 silex 和 symfony2 组件完全陌生^_^ 谢谢,任何建议真的很感激

您(至少)缺少一个必需的元字段:

  • created_at (datetime, not null): 记录创建时间
  • updated_at (datetime, not null): 上次编辑记录的时间
  • version (int, not null): 记录的版本,每次编辑递增
  • deleted_at(日期时间):如果不为空:记录被(软)删除的时间

在您的案例中,完整的 table 创建 SQL 如下所示:

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;