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

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.
    – piotrpog
    Feb 28 '20 at 10:50
  • Please confirm and/or upvote for this answer it you think this is a right and viable solution :) Feb 28 '20 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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