我尝试使用 symfony 组件找到一种更快的方式来为现有数据库、CRUD、 Composer 方式生成 UI。
找到 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 组件完全陌生 ^_^ 谢谢,任何建议都非常感谢
最佳答案
您(至少)缺少一个必需的元字段:
- created_at (datetime, not null): 记录创建时间
- updated_at(datetime, not null): 最后一次编辑记录的时间
- version (int, not null): 记录的版本,随着每次编辑而递增
- deleted_at (datetime):如果不为空:记录被(软)删除的时间
在您的案例中,完整的表创建 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/