0

I have an issue with my PhpStorm using incorrect namespaces when creating a new class.

Example: I have a module named Booking. Inside Booking I want to create a controller called StatusController. The directory the controller class will be created in is Booking/src/Controller, and after being created it's namespace should be Booking\Controller, but my IDE is making it Booking\src\Controller

The Booking module is located inside a module directory in my project, and the module directory has been set as a Source Folder for my project:

source folder setup

Could anyone please help me find what setting I have to change to make namespaces auto generate as Booking\Controller instead of Booking\src\Controller?

1
  • 1
    Mark your Booking\src folder as Source root that maps to Booking namespace. P.S. AFAIK it should be PSR-4 and not PSR-0 (as you have src in the middle that is not present in namespace) Commented Jun 18, 2018 at 23:15

1 Answer 1

5

Open Settings --> Directories;

Choose your ../module/Booking/src folder;

Right-click --> Mark as Sources;

On the right panel, you should see your folder (blue). Click on P with little arrow - Edit Root Properties. In input field Package prefix put as Booking;

Apply/Ok all windows

enter image description here

On screenshot, I have different paths, but you should get the gist.

Now in New Class dialog window in the field Namespace you can choose namespace between 'with src' and 'without'.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I'd like to upvote multiple times. This has been bugging me for a long time. Thanks!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.