The problem is the checkboxlist selection which is a multiple select. When I remove the following mailer code from the controller, the form is emailed… '{serviceItem}' => $model->selection,
In the model, the following explode and implode is used for putting the selection into the db table correctly…
public function afterFind()
{
$this->selection=explode(',',$this->selection);
return true;
}
/*implode your selection */
public function beforeSave()
{
$this->selection=implode(',',$this->selection);
return true;
}
If implode beforeSave…
[quote=”php manual”] Returns a string containing a string
representation of all the array elements in the same order, with the
glue string between each element.[/quote]
And the mailer $message = strtr returns a string from the array…
[quote=”phpmanual”]strtr – If given two arguments, the second should be an array in the
form array(‘from’ => ‘to’, …). The return value is a string where all the occurrences of
the array keys have been replaced by the corresponding values…
$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. Why is there an error? and…
Q. What is the solution for the $model->selections to be sent in the email?
Answer:
First
strtr()expects the array to be of the formarray('stringFROM'=>'stringTO')and notarray('stringFROM'=>array(...)).You are getting the second format(and hence the error) because
$model->selectionis an array, since you have done anexplode()inafterFind().afterFind()is called whenever you load a model with any of thefindmethods of CActiveRecord(i.efind(),findAll(),findByPk(),findByAttributes(), and so on), and if i am correct you are calling one of those of methods to get your current model.Answer:
In this case you can simply do an
implode()again, to get a string: