0

后端:

后端小节经理

前端:

前端成员部分

我想要完成的是一个前端表单,它允许成员更新他们存档的电话号码。电话号码存储在他们自己的部分中,并通过后端的子部分管理器附加到成员记录。

cf,交响乐 CMS 讨论


Symphony 2.3.6 小节管理器 3.5.1

4

2 回答 2

0

我最初的答案有点奏效,但它正在重新发明轮子。Symphony 的事件可以处理我在上面记下的场景。通过使用本机事件行为,您不必重新编码用户反馈等。

我强烈推荐@Brendo 的这篇文章(有点过时)。

注意:self::ROOTELEMENT不推荐使用对的引用,您应该$this->ROOTELEMENT改用。

于 2014-02-27T21:28:37.427 回答
0

伪代码

1. Identify new phone numbers
2. Create New Entry Objects for each number
3. Create array of entry objects that includes 
    3.1 existent numbers being edited
    3.2 new numbers being added
4. Update all numbers with new/edited values
5. Commit Numbers Entries to the Phone Number Section in DB
6. Update the Member entry to reflect the ID of the new phone number
7. Commit the Member Entry to the Members Section in the DB

我有这个工作,它将新电话号码保存到电话号码部分(伪代码 #s 1-5;我还不担心编辑现有号码):

foreach($_POST['fields']['phone-numbers-new'] as $hash => $field)
{
    $data = array();
    $data[$ids['phoneNumbers']['fields']['type']]['handle'] = General::createHandle($field['type']);
    $data[$ids['phoneNumbers']['fields']['type']]['value'] = $field['type'];
    $data[$ids['phoneNumbers']['fields']['number']]['handle'] = General::createHandle($field['number']);
    $data[$ids['phoneNumbers']['fields']['number']]['value'] = $field['number'];
    $data[$ids['phoneNumbers']['fields']['added_by']]['author_id'] = "1";
    $data[$ids['phoneNumbers']['fields']['active']]['value'] = "yes";


    $newPNs = EntryManager::create();
    $newPNs->set('section_id', "{$ids['phoneNumbers']['sectionID']}");
    $newPNs->setDataFromPost($data);
    $newPNs->setData($ids['phoneNumbers']['fields']['type'],$data[$ids['phoneNumbers']['fields']['type']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['number'],$data[$ids['phoneNumbers']['fields']['number']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['added_by'],$data[$ids['phoneNumbers']['fields']['added_by']]);
    $newPNs->setData($ids['phoneNumbers']['fields']['active'],$data[$ids['phoneNumbers']['fields']['active']]);

    $ids['newPNs'][] = $newPNs->get('id');

    $newPNs->commit(); //adds the new phone number to the Phone Number Section

}

然后我用新的电话号码更新会员条目:

$entries = EntryManager::fetch($ids['entry']);
$member = $entries[0];

$data = array(); // reset data array

$data[$ids['phoneNumbers']['fieldID']] = $member->getData($ids['phoneNumbers']['fieldID']);
for($i = 0; $i < count($ids['newPNs']); $i++)
{
    $index = count($data[$ids['phoneNumbers']['fieldID']]['relation_id']) + $i;
    $data[$ids['phoneNumbers']['fieldID']]['relation_id'][$index] = "{$ids['newPNs'][$i]}";
}
$member->setData($ids['phoneNumbers']['fieldID'],$data[$ids['phoneNumbers']['fieldID']]);
$member->commit();

这适用于添加新的电话号码。在提交成员条目之前,应在部分中更新编辑的数字,结果也是成功的。

于 2014-02-27T06:35:43.673 回答