tresero
(Jongriffinjr)
December 20, 2013, 3:33am
1
I have not programmed seriously in over 4 years, so yeah, I am rusty
I am trying to figure out how to get a simplexml object to convert to CArrayDataProvider and then on to a CGridView.
Sounds simple, but I can’t get it to work. The issue is that nothing ever shows on the page.
I am getting data from an Amazon API, and converting it to an array. I pass it to my view and send it to CGridView. I know the data is there because a print_r shows the array. I can also echo the array data.
Probably something simple, but I can’t get it to work.
Here is the controller:
$amazon = new AmazonProductAPI($public, $private, $site, $affiliate_id);
//define('keyword_limit', 25);
try
{
$result = $amazon->queryAmazon($this->single);
}
catch(Exception $e)
{
echo $e->getMessage();
echo "<p />";
die();
}
$arrayDataProvider=new CArrayDataProvider($result,array('id'=> false));
$this->render('display',array('dataProvider'=>$arrayDataProvider));
Here is the view:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $content
)
);
tresero
(Jongriffinjr)
December 20, 2013, 3:35am
2
BTW, this is the error.
array_slice() expects parameter 1 to be array, object given
Ravi005
(Bhalodiyaravi)
December 20, 2013, 5:37am
3
If this is your final code then you have to first replace variable $dataProvider in place of $content.
Ravi005
(Bhalodiyaravi)
December 20, 2013, 5:56am
4
Make sure your $result array should be like following structure:
Array
(
[0] => Array
(
[id] => 0
[columnName1] => value1
[columnName2] => value2
)
)
tresero
(Jongriffinjr)
December 20, 2013, 4:12pm
5
That error was fixed, but I still get nothing.
tresero
(Jongriffinjr)
December 20, 2013, 4:15pm
6
Here is a snippet of the dataprovider and BTW, this works perfectly outside YII. I have this as a one off site and it works fine.
Total listings: CArrayDataProvider Object ( [keyField] => id [rawData] => SimpleXMLElement Object ( [OperationRequest] => SimpleXMLElement Object ( [RequestId] => f213ab53-de92-457b-bab7-58c587ab7bd0 [Arguments] => SimpleXMLElement Object ( [Argument] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Operation [Value] => ItemSearch ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Service [Value] => AWSECommerceService ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Signature [Value] => yXNL+e7AvInKl9aFPxEUBnC074MjLn+FsJTBm5UBUPs= ) ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AssociateTag [Value] => jongriffcom-20 ) ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Version [Value] => 2011-08-01 ) ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Keywords [Value] => odesk ) ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => AWSAccessKeyId [Value] => 0SG50YF2VNQJZRST0SG2 ) ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Timestamp [Value] => 2013-12-20T16:15:42Z ) ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => ResponseGroup [Value] => Medium ) ) [9] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => SearchIndex [Value] => Books ) ) ) ) [RequestProcessingTime] => 0.0715020000000000 ) [Items] => SimpleXMLElement Object ( [Request] => SimpleXMLElement Object ( [IsValid] => True [ItemSearchRequest] => SimpleXMLElement Object ( [Keywords] => odesk [ResponseGroup] => Medium [SearchIndex] => Books ) ) [TotalResults] => 83 [TotalPages] => 9 [MoreSearchResultsUrl] => http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001&location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fsearch%3Fkeywords%3Dodesk%26url%3Dsearch-alias%253Dstripbooks&linkCode=xm2&tag=jongriffcom-20&SubscriptionId=0SG50YF2VNQJZRST0SG2 [Item] => Array ( [0] => SimpleXMLElement Object ( [ASIN] => B009QR9L44 [DetailPageURL] => http://www.amazon.com/Unofficial-Client-Success-Guide-oDesk-ebook/dp/B009QR9L44%3FSubscriptionId%3D0SG50YF2VNQJZRST0SG2%26tag%3Djongriffcom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB009QR9L44 [ItemLinks] => SimpleXMLElement Object ( [ItemLink] => Array ( [0] => SimpleXMLElement Object ( [Description] => Technical Details [URL] => http://www.amazon.com/Unofficial-Client-Success-Guide-oDesk-ebook/dp/tech-data/B009QR9L44%3FSubscriptionId%3D0SG50YF2VNQJZRST0SG2%26tag%3Djongriffcom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB009QR9L44 ) [1] => SimpleXMLElement Object ( [Description] => Add To Baby Registry [URL] => http://www.amazon.com/gp/registry/baby/add-