0

I am creating a PHP project using the MVC pattern. You can see the directory structure below.

My question: where can I put utility classes like Email and Date?

Project directory structure:

- app/
   - Models/
   - Controllers/
   - Views/
- vendor/
- composer.json
- composer.lcok

2 Answers 2

2

Like any other utility class/helper function/convenience whatever, where to put it depends on who's using it. If only M uses it, then maybe it belongs in the Model folder. If your M, V and C are all using Dates, then maybe Date belongs in a separate folder from all three. You don't have to put every piece of code in one of those three folders.

0

It's a good practice to have a separate directory like "Services" or "Utilities". Then your MVC layers can use these functionalities.

Project directory structure:

- app/
   - Models/
   - Controllers/
   - Views/
   - Services/
      - Mail/Mailer.php
      - Mail/MailTrap.php
      - Mail/AmazonSES.php
      - Sms/Provider.php
      - Auth/OtpProviider.php
- vendor/
- composer.json
- composer.lcok

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.