views:

23

answers:

1

The following code fails throws a Zend_Controller_Exception ("Invalid value passed to setPost(); must be either array of values or key/value pair")

/** Model_Audit_Luminaire */
$luminaireModel = new Model_Audit_Luminaire();
if (!$fixture = $luminaireModel->getScheduleItem($scheduleId)) {
    $this->fail('Could not retrieve fixture from database');
}
$fixtureArray = $fixture->toArray();

$this->getRequest()
    ->setMethod('POST')
    ->setPost($fixtureArray);

I did a var_dump() to ensure $fixtureArray was the correct type, and formatted properly...no visible problems.

+1  A: 

Are any of the columns in your schedule item row nullable?

The setPost() method calls itself for each key/value pair you pass in an array. But if any value is null, it throws an exception.

You may have to loop over the array and setPost() only values that are non-null:

$this->getRequest()->setMethod("POST");
foreach ($fixtureArray as $key => $value) {
  if ($value === null) { continue; }
  $this->getRequest()->setPost($key, $value);
}

Or else ensure that the row you fetch from the database in your getScheduleItem() method contains no nulls.

Bill Karwin
Perfect. It was the null values that caused the error. Thank you very much!
webjawns.com