Skip to content

Cant get namespaces to work, need help #15315

Answered by bahadirbirsoz
TimurFidarov asked this question in Q&A
Discussion options

You must be logged in to vote

It's been a while but I wanted to add a quick answer for future reference.

Your controllers' namespace is App/Controllers and it is located in app/controllers directory.
Similarly, your models will have App/Models namespace and will be located in app/models.

In this case all you need to register is the App Namespace to APP_PATH. Each namespace that begins with App\ will be mapped with directory names. In other words, each class file under app directory and its subdirectories will be expected to have relatively mapped directory names as namespace (of course camel case).

$loader->registerNamespaces([
    'App' => APP_PATH,
])->register();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by TimurFidarov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants