简体   繁体   English

Symfony 3和Sonata管理员

[英]Symfony 3 and Sonata Admin

I wish to know simply if it is possible to preload the create entity form with given values. 我想简单地知道是否可以使用给定值预加载创建实体表单。

My application has a Daily Schedule view with 30 minute intervals. 我的应用程序具有30分钟间隔的“每日计划”视图。 I want the user to be able to click on a time (eg:12:30) on the Daily Schedule and have it preload a Booking entity form along with the current date. 我希望用户能够单击“每日时间表”上的某个时间(例如:12:30),并使其与当前日期一起预加载“预订实体”表单。

I have searched to no avail a solution, I would have thought this would be a common action. 我一直没有找到解决方案,我认为这将是一个常见的动作。

I figure I need to access the instantiated object (the Booking) prior to it binding to the request however this is all handled by Sonata Admin. 我认为我需要在绑定到请求之前访问实例化的对象(预订),但这全部由Sonata Admin处理。 Is it possible to simply override the Create action to preload the form? 是否可以简单地覆盖Create操作来预加载表单?

Thank you in advance. 先感谢您。

Yes, it is. 是的。 You could set defaults on your Booking entity or overwrite getNewInstance() in your Admin class, like so: 您可以在Booking实体上设置默认值,或者在Admin类中覆盖getNewInstance() ,如下所示:

public function getNewInstance()
{
    $object = parent::getNewInstance();

    $object->setDefaults();

    return $object;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM