I have an array which needs to be converted into an XML view and show the same in a view page. The array looks something like this:
Array
(
[0] => Cake\ORM\Entity Object
(
[id] => 1
[user_id] => 3
[title] => Article 1
[body] => Validation is commonly used.
[created] => Cake\I18n\Time Object
(
[time] => 2016-01-29T13:51:43+0000
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\Time Object
(
[time] => 2016-01-30T13:51:43+0000
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[repository]] => AppManager.Articles
)
[1] => Cake\ORM\Entity Object
(
[id] => 2
[user_id] => 1
[title] => Article 2
[body] => The API documentation
[created] => Cake\I18n\Time Object
(
[time] => 2016-01-03T13:51:58+0000
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\Time Object
(
[time] => 2016-01-03T13:51:58+0000
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[repository]] => AppManager.Articles
)
[2] => Cake\ORM\Entity Object
(
[id] => 3
[user_id] => 2
[title] => Article 3
[body] => Now that you’ve created a validator and added the rules you want to it, you can start using it to validate data. Validators are able to validate array data. For example, if you wanted to validate a contact form before creating and sending an email you could do the following:
[created] => Cake\I18n\Time Object
(
[time] => 2016-01-03T13:52:19+0000
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\Time Object
(
[time] => 2016-01-03T13:52:19+0000
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[repository]] => AppManager.Articles
)
[3] => Cake\ORM\Entity Object
(
[id] => 8
[user_id] => 1
[title] => Sample webservices post
[body] => Get the cookies from the response. Cookies will be returned as an array with all the properties that were defined in the response header. To access the raw cookie data you can use header()
[created] => Cake\I18n\Time Object
(
[time] => 2016-02-02T11:06:14+0000
[timezone] => UTC
[fixedNowTime] =>
)
[modified] => Cake\I18n\Time Object
(
[time] => 2016-02-02T11:06:14+0000
[timezone] => UTC
[fixedNowTime] =>
)
[[new]] =>
[[accessible]] => Array
(
[*] => 1
)
[[dirty]] => Array
(
)
[[original]] => Array
(
)
[[virtual]] => Array
(
)
[[errors]] => Array
(
)
[[repository]] => AppManager.Articles
)
)
Let me tell you what I've done so far.
public function getDataFromWebServices(){
$articles = $this->Articles->find("all")->toArray();
$this->set([
"articles" => $articles,
"_serialize" => ["articles"]
]);
// Not sure what to do in the view after serializing this array
$xmlObject = Xml::fromArray($articles);
$xmlString = $xmlObject->asXML(); // Gives an error "Invalid Input"
}
Any help would be appreciated.
Peace! xD