Can i use element queries in general.php file? I wanted to set loginPath based on entry query, like this:

'loginPath' => Craft::$app->entries->section('login')->one()->url ?? false,

Hovewer, i get error:

( ! ) Fatal error: Uncaught Error: Class 'Craft' not found in C:\xampp\htdocs\xxx\config\general.php on line 40

1 Answer 1


Add this at the top of config/general.php file:

use craft\elements\Entry;

And change your loginPath value to:

'loginPath' => function() {
   return Entry::find()->section('login')->one()->url ?? null;
  • Thanks! I tried something similar - i pasted "use Craft", but it didnt helped. I wonder why. Commented Feb 28, 2020 at 10:50
  • Please confirm and/or upvote for this answer it you think this is a right and viable solution :)
    – Romain P.
    Commented Feb 28, 2020 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.