Drupal では、最初にプライベート メッセージの本文に表示されるメールをシリアル化し、次のように MySQL に保存しました。
function prvtmsg_list($body) {
$notify = array();
if (isset($body->emails)) {
$notify['mid'] = $body->mid;
$notify['emails'] = serialize($body->emails);
}
if (isset($body->vulgar_words) {
$notify['mid'] = $body->mid;
$notify['vulgar_words'] = serialize($message->vulgar_words);
}
if (isset($notify['mid'])) {
drupal_write_record('prvtmsg_notify', $notify);
}
}
後でそれらを取得しようとすると、電子メールのユーザー化が失敗し、次のように取得します。
function prvtmsg_list_notify() {
// Select fields from prvtmsg_notify and Drupal pm_message tables
$query = db_select('prvtmsg_notify', 'n');
$query->leftJoin('pm_message', 'm', 'n.mid = m.mid');
$query->fields('n', array('mid', 'emails', 'vulgar_words'));
$query->fields('m', array('mid', 'author', 'subject', 'body', 'timestamp'));
orderBy('timestamp', 'DESC');
$query = $query->extend('PagerDefault')->limit(20);
$result = $query->execute()->fetchAll();
$rows = array();
foreach ($result as $notify) {
$rows[] = array(
$notify->author,
$notify->subject,
implode(', ', unserialize($notify->emails)),
implode(', ', unserialize($notify->vulgar_words)),
);
}
$build = array();
$build['table'] = array(
'#theme' => 'table',
'#header' => array(
t('Author'),
t('Message subject'),
t('Emails captured'),
t('Vulgar Words Captured'),
),
'#rows' => $rows,
);
$build['pager']['#theme'] = 'pager';
return $build;
}
メールのシリアライズ方法が間違っているのでしょうか?なぜなら:
dpm(unserialize($notify->emails);
Array, Array, Array を与える - つまり:
Array(
[0] => Array() [1] => Array() [2] => Array() [3] => Array()
)
意外なことに、未連載の下品な言葉がちゃんと表示されています!次のようにメールをシリアル化できるかどうかはわかりません。
$notify['emails'] = serialize (array($body->emails));
過去に、シリアル化解除がうまくいかなかった正確な状況に直面しました。私には明確ではない何かがあり、それを学ぶ必要があります。誰かが確認したり、何が悪いのか教えてもらえますか?
注意上記のコードはメモリからのものであり、現在アクセスできないため正確ではない可能性があります。