问题在于复选框列表的选择是多选。当我从控制器中删除以下邮件程序代码时,表单将通过电子邮件发送。。。'{serviceItem}' => $model->selection,
在模型中,下面的爆炸和内爆用于将选择正确地放入数据库表中。。。
public function afterFind()
{
$this->selection=explode(',',$this->selection);
return true;
}
/*implode your selection */
public function beforeSave()
{
$this->selection=implode(',',$this->selection);
return true;
}
如果之前内爆保存。。。
[quote="php-manual"]返回一个包含字符串的字符串以相同顺序表示所有数组元素每个元素之间的胶水串。[/quote]
邮件程序$message = strtr
从数组中返回一个字符串。。。
[quote="phpmanual"]strtr-如果给定两个参数,第二个参数应该是form数组('from'=>'to',…)。返回值是一个字符串,其中数组键已被相应的值替换。。。
$message = strtr ('Submitted on: {submissionDate}
Name: {firstName} {lastName}
Service Item: {serviceItem}
Visitor Comments: {message}', array(
'{submissionDate}' => $model->date,
'{firstName}' => $model->firstName,
'{lastName}' => $model->lastName,
'{serviceItem}' => $model->selection,
'{message}' => $model->comments));
Q。为什么会出现错误?和
Q要在电子邮件中发送的$model->选择的解决方案是什么
Q。为什么会出现错误?
答案:
第一个CCD_ 3期望阵列的形式为array('stringFROM'=>'stringTO')
而不是array('stringFROM'=>array(...))
。
您得到的是第二种格式(,因此出现错误),因为$model->selection
是一个数组,因为您在afterFind()
中完成了explode()
。
每当您使用CActiveRecord的任何find
方法(即find()
、findAll()
、findByPk()
、findByAttributes()
等)加载模型时,都会调用afterFind()
,如果我是正确的,您将调用其中一个方法来获得当前模型。
Q。$model的解决方案是什么;要在电子邮件中发送的选择?
答案:
在这种情况下,您可以简单地再次执行implode()
,以获得字符串:
'{serviceItem}' => implode(',',$model->selection);