I am currently having issues loading a collection of objects into an array of objects based on my user class. Currently the error I keep getting is: "Fatal error: Call to a member function getSongName() on a non-object " How do I convert the backendless collection into an array of class objects?
Current Code:
$songs = Backendless::$Persistence->of("Songs")->find($data_query_or_relation_depth = null);
$songArray = $songs->getAsClass();
foreach ($songArray as $song)
{
echo $song->getSongName();
}
As for the Song Class we can see that everything is set up correctly
Songs.php
<?php
namespace juiceMusic;
class Songs
{
private $songName;
private $link;
private $songLocation;
private $trackArtwork;
private $relatedAlbum;
public function __construct($SongName, $Link, $SongLocation, $TrackArtwork, $RelatedAlbum)
{
$this->songName = $SongName;
$this->link = $Link;
$this->songLocation = $SongLocation;
$this->trackArtwork = $TrackArtwork;
if ($RelatedAlbum != null) {
$this->relatedAlbum = $RelatedAlbum;
}
}
/* GETTERS AND SETTERS */
public function getSongName()
{
return $this->songName;
}
public function setSongName($SongName)
{
$this->songName = $SongName;
}
public function getLink()
{
return $this->link;
}
public function setLink($link)
{
$this->link = $link;
}
public function setSongLocation($location)
{
$this->songLocation = $location;
}
public function getSongLocation()
{
return $this->songLocation;
}
public function getRelatedAlbum()
{
return $this->relatedAlbum;
}
public function setRelatedAlbum($relatedAlbum)
{
$this->relatedAlbum = $relatedAlbum;
}
public function getTrackArtwork()
{
return $this->trackArtwork;
}
public function setTrackArtwork($trackArtwork)
{
$this->trackArtwork = $trackArtwork;
}
}
?>