I'm attempting to get a user's ID from the URL of a page containing his/her username. For instance, /team/people/john-smith/
Here's my code:
/*
* Get user ID to then find articles made by this user
*/
$user = $modx->newQuery('modUser');
$user->where(array(
'username' => $author //(john-smith)
));
$author = $modx->getObject('modUser', $user);
/*
* Get articles made by this user
*/
$ar = $modx->newQuery('modResource');
$ar->where(array(
'createdby' => $author->id,
'class_key' => 'Article',
'parent' => $parentID
));
$ar->sortby('publishedon', 'DESC');
$articles = $modx->getCollection('modResource', $ar);
/*
* Loop through all articles made by user
*/
foreach ($articles as $article) {
/*
* Get article template variable image
*/
$image = $article->getTVValue('articleimage');
$modx->setPlaceholders(array('articleimage' => $image));
/*
* Get all articles by author
*/
$allArticles .= $modx->getChunk('curiosityAuthor', $article->toArray());
}
//etc...
My issue is I'm receiving an error ONLY when I am NOT logged in. My code returns a 404 error with a 503 error within like so:
In my Error Logs I see this:
"Instantiated a derived class modUser that is not a subclass of the requested class modResource"
Is modUser object only accessible when logged in? (I'm reasonably new to ModX)
If the answer is yes to above then how do I work around getting an ID of a user from a username with xPDO without running a custom query.
Thanks!