I have the following php code that works:
global $m, $db;
$collection = $db->locations;
try{
$cursor = $collection->find();
return $cursor;
} catch(MongoCursorException $e) {
return false;
}
global $m, $db;
$collection = $db->locations;
try{
$cursor = $collection->find().sort({name:1});
return $cursor;
} catch(MongoCursorException $e) {
return false;
}
Parse error: syntax error, unexpected '{' in /var/www/html/myapp/models/locations_model.php on line 23
Try
$cursor = $collection->find()->sort(['name' => 1]);
Your error is because you are not sending an array to the sort, which it expects, see PHP mongocursor sort