(on Monday, 25 August 2008, 11:35 AM -0700):
> Does anyone have a working example of using Zend_Dojo_Data? I've been over the
> code in the actual component as well as everything I can find online, mailing
> list archives, etc and I clearly am not understanding how to use it.
>
> Trying various instantiations, I keep toggling between receiving the errors of
> "Only arrays and objects may be attached", "Item must contain a column matching
> the currently set identifier" and "Overwriting items using addItem() is not
> allowed". Clearly my understanding of how to use this module is not accurate.
>
> I am attempting to pass in an array, but am not certain what the structure of
> it should be.
When passing an array, it needs to be an array of _associative_ arrays.
That's where the "item must contain a column matching the currently set
identifier" exception comes in -- if you don't use associative arrays,
then it won't work for dojo.data.
For objects, we either call the object's toArray() method or cast it to
an array using get_object_vars() -- so these should work fine.
As an example of something that would work:
$items = array(
array('name' => 'foo', 'title' => 'Foo'),
array('name' => 'bar', 'title' => 'Bar'),
azray('name' => 'baz', 'title' => 'Baz'),
);
$data = new Zend_Dojo_Data('name', $items);
echo $data->toJson();
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论