namespace capitalisation

Hi, I've just moved to codeigniter 4 which uses namespaces and am trying to set it up correctly in phpstorm.

The project structure is shown below. In the Messages.php file, first line is "namespace App\Controllers\Options;". The site works fine but phpstorm flags the namespace line as an error and says "namespace doesnt match the psr0/psr4 structure". If i rename the "app" folder to "App" phpstorm is happy but the site doesn't work. I have project/settings/sources as /home/develop/cig4/mysite. What is the correct way set up the project? Many thanks, Bill

/home/develop/cig4/mysite

      app

            Controllers (folder)

                   Messages.php (this is a controller)

            other folders eg Config, Database etc

      public

 

0
2 comments

Hi there,

I see some contradictions here.

On one hand you have

In the Messages.php file, first line is "namespace App\Controllers\Options;"

but the folder structure tells that the file path is

/home/develop/cig4/mysite/app/Controllers/Messages.php

I do not see "Options" bit there at all...

 

If i rename the "app" folder to "App" phpstorm is happy but the site doesn't work.

1) The correct spelling is PhpStorm.

2) Go to "Settings/Preferences | Directories" and mark your "app" folder as Source Root -- use "App\" as a package prefix there, so at the end it will look like this:

This will tell to the IDE that your app folder is mapped to App\ namespace bit.

0

thanks a million, that solved it, now i can work in peace

Bill

0

Please sign in to leave a comment.