我试图找到一种更快的方法来为现有数据库、CRUD、composer 方式生成 UI,使用 symfony 组件。
找到 CRUDlex 。使用 composer 进行安装,同时设置 CRUDlex sample
它工作正常,直到我在示例 crud.yml 中添加新表定义
category:
label: Category
table: category
fields:
name:
type: text
label: Name
required: true
unique: true
在 yml 中添加了什么表,访问 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 组件完全陌生^_^
谢谢,任何建议都非常感谢
最佳答案
您缺少(至少)必需的元字段之一:
在您的情况下,完整的表创建 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;
关于php - 在 yaml 中添加新表时,CRUDlex 不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41210836/