我在在线学习网站项目的学校项目中使用了EasyAdmin。
教师可以添加编队,附属于编队的部分以及属于部分的教训。我为每个设置了三个CRUD,并查询,以便登录的用户只能看到他们创建的内容。
问题是,在添加新条目时,EasyAdmin在数据库中未设置登录中的登录,我会收到以下错误:
执行查询时发生了一个例外:sqlstate [23000]:完整性约束违规:1048列'user_id'不能null
我得出的位置,如果没有USER_ID,您将无法在数据库中添加一个条目但是我似乎找不到可以设置easyAdmin的位置,因此在添加新条目时它总是会通过user_id。您可以在某个地方编辑添加操作吗?
谢谢!
I'm using easyadmin with my online learning website project for school.
Teachers can add formations, sections which are attached to formations, and lessons which belong to sections. I set up three cruds for each, and queries so the logged in user can only see content they created.
The issue is that when adding a new entry, easyadmin doesn't set up the logged in user_id in the database, and I get the following error:
An exception occurred while executing a query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null
I get where it's coming from, you can't add an entry to the database without the user_id since it's not nullable, but I can't seem to find where I can set up easyadmin so it always passes the user_id when adding a new entry. Can you edit the add action somewhere?
Thanks!
发布评论
评论(1)
如 $ this-> getUser())在您的
Abstract> AbstractCrudController :: CreateNentity
)中。 >方法。As shown in the docs example code below, you need to manually set the user on your entity (currently logged-in user is returned by
$this->getUser()
) in yourAbstractCrudController::createEntity
method.