【发布时间】:2017-05-07 02:31:12
【问题描述】:
我是 symfony 初学者。 我的表格有很大问题 我想将数据保存到我的表名称活动中,如下所示:
Campaigns:
id, user_id, recipients, message, sender, type, created
还有下一个
我在收件人系统中有 2 个表
contacts_groups:
id, user_id, name, description, created
和
contacts:
id, user_id, group_id, email, city, created.
现在假设我的表有以下记录:
contacts_groups:
id, user_id, name, description, created
1, 1, Test Group, Newest recipients, 2016-20-02 14:24:00
2, 1, Awesome Group, Pro players, 2016-10-02 11:22:41
contacts:
id, user_id, group_id, email, city, created
1, 1 , 1, exmple@email.com, New York, 2016-12-12 12:12:12
2, 1 , 1, test@emailer.com, New York, 2016-12-12 12:12:12
3, 1 , 2, proplayer@games.com, New York, 2016-12-12 12:12:12
现在我想用 2 个表格记录做一个表格 示例:
TextField => text for sender name row
ChoiceType => select with options with contacts_groups records
ChoiceType => select with options with contacts where group_id == choosed contacts_groups record above.
我有那个代码:
class CampaignsType extends AbstractType{
public function buildForm(FormBuilderInterface $builder, array $options) {
$Campaigns = $options['data'];
$user = $Campaigns->tmpusr; // variable transferred from the controller ( logged user id )
$builder
->add('sender', TextType::class, array(
'trim' => true,
'label' => 'Odbiorca',
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('class' => 'form-control', 'maxlength' => '11')
))
->add('recipients', EntityType::class, array(
'label' => 'Grupa odbiorców',
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('class' => 'form-control'),
'class' => 'MyAppPanelBundle:ContactsGroups',
'query_builder' => function (\Doctrine\ORM\EntityRepository $er) use ($user) {
return $er->createQueryBuilder('u')
->select('u')
->add('where', 'u.user_id = ' . $user)
->orderBy('u.id', 'DESC');
},
'choice_value' => 'id',
'choice_label' => 'name',
));
}
有人知道如何从数据库中添加下一个字段,其中group_id 将与所选组的ID 相同?
谢谢大家。
【问题讨论】:
-
要实现这一点,您需要使用 ajax 发送带有选定
group的请求,并作为响应获取contactsdoc chapter 的列表
标签: arrays forms symfony collections