2008年12月11日星期四

Re: [fw-db] Zend_Db_Row toarray() is detected as string type?

Right... got it. The problem was due to me setting defaults on a form that
has subforms.
quick example.

$form = new Zend_Form();
$form->addSubForm(new Zend_Form(), 'form1');
$form->addSubForm(new Zend_Form(), 'form2');

$table = new SomeTable(); //extends Zend_Db_Abstract
$row = $table->fetchRow($table->select()->where('id =
?',$request->getParam('id')));
$form->setDefaults($row->toArray());

Somehow this sequence regards the array that $row->toArray() as a string.

Of course, the error was on my part. I guess.

Instead of using the setDefaults() method on the parent form, I used
setDefaults() on each of the subforms.

$form->getSubForm('form1')->setDefaults($row->toArray());


rvdavid wrote:
>
> For some reason, the output of the following code snippet:
>
> // from within a domain model
> $table = $this->getTable('Users'); // returns TDG
> $row = $table->fetchRow($table->select()->where('id =
> ?',$request->getParam('id'))); // returns Zend_Db_Row_Abstract
> $this->getForm()->setDefaults($row->toArray(),
> explode(',',$row->privileges));
>
> is detected as a string by Zend_Form::setDefaults(), returns the following
> error:
>
> Catchable fatal error: Argument 1 passed to Zend_Form::setDefaults() must
> be an array, string given, called in --- snip ---/library/Zend/Form.php on
> line 1214
>
> As a workaround, I've removed the array type hint from the Zend_Form
> setDefalult method, but only after 90 minutes of trying to figure it out.
>
> The strange thing is - if I go to the toArray() method of the Row abstract
> class and changed it to return array() instead of $this->_data, then it
> works fine. looked all over the code to see how it was coming about and it
> all seemed pretty clean.
>
> Don't have time to provide more info, but it's there for the asking if
> anyone is interested.
>
> ...
>


-----

R. Villar David
Lead Developer, DevProducts Pty Ltd
p: +61 2 9648 3777 f: +61 2 9648 6988
w: http://www.devproducts.com
--
View this message in context: http://www.nabble.com/Zend_Db_Row-toarray%28%29-is-detected-as-string-type--tp20954917p20958822.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: