$check = "home";
$resourses = $modx->getCollection('modResource',array(
'alias' => $check
));
foreach ($resourses as $resourse) {
$output = $resourse->get('alias');
}
if (isset($output)) {return "True";} else {return "False";}
This question has been answered by markh. See the first response.
1- modx already checks that an alias is unique.
$doc = $modx->newObject('modDocument');
$doc->set('parent','12');
$doc->set('pagetitle','mypagetitle');
$doc->set('alias','myalias');
$doc->set('template','3');
$doc->save();
But filter is not the same thing as comparison. Or have I misunderstood something?
2- getCollection returns the resources filtered by alias, why check again?
How does he look without foreach?
2- getCollection returns the resources filtered by alias, why check again?
$results = $modx->getCount('modResource', ['alias' => $check]);
return $results > 0 ? 'True' : 'False';