Phalconn Dispatcher and Loader registerNamespaces
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am learning Phalcon (php).
This is an example from github using phalcon with the following folder structure
single-namespaces/
├── apps
│ ├── controllers
│ │ ├── IndexController.php
│ │ └── ProductsController.php
│ ├── models
│ │ └── Products.php
│ └── views
│ └── products
│ └── index.phtml
└── public
└── index.php
in public/index.php, $loader registered namesapces
$loader->registerNamespaces(
[
'SingleControllers' => '../apps/controllers/',
'SingleModels' => '../apps/models/'
]
);
$dispatcher also set the namespace
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('SingleControllers\');
return $dispatcher;
});
If I remove $dispatcher->setDefaultNamespace('SingleControllers\')
, error saying IndexController handler class cannot be loaded
Is that mean when loading the classes in namespaces, Dispatcher/Router will ignore the setting of loader? We must explicitly state the namespace for Dispatcher/Router?
phalcon loader dispatcher
add a comment |
I am learning Phalcon (php).
This is an example from github using phalcon with the following folder structure
single-namespaces/
├── apps
│ ├── controllers
│ │ ├── IndexController.php
│ │ └── ProductsController.php
│ ├── models
│ │ └── Products.php
│ └── views
│ └── products
│ └── index.phtml
└── public
└── index.php
in public/index.php, $loader registered namesapces
$loader->registerNamespaces(
[
'SingleControllers' => '../apps/controllers/',
'SingleModels' => '../apps/models/'
]
);
$dispatcher also set the namespace
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('SingleControllers\');
return $dispatcher;
});
If I remove $dispatcher->setDefaultNamespace('SingleControllers\')
, error saying IndexController handler class cannot be loaded
Is that mean when loading the classes in namespaces, Dispatcher/Router will ignore the setting of loader? We must explicitly state the namespace for Dispatcher/Router?
phalcon loader dispatcher
add a comment |
I am learning Phalcon (php).
This is an example from github using phalcon with the following folder structure
single-namespaces/
├── apps
│ ├── controllers
│ │ ├── IndexController.php
│ │ └── ProductsController.php
│ ├── models
│ │ └── Products.php
│ └── views
│ └── products
│ └── index.phtml
└── public
└── index.php
in public/index.php, $loader registered namesapces
$loader->registerNamespaces(
[
'SingleControllers' => '../apps/controllers/',
'SingleModels' => '../apps/models/'
]
);
$dispatcher also set the namespace
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('SingleControllers\');
return $dispatcher;
});
If I remove $dispatcher->setDefaultNamespace('SingleControllers\')
, error saying IndexController handler class cannot be loaded
Is that mean when loading the classes in namespaces, Dispatcher/Router will ignore the setting of loader? We must explicitly state the namespace for Dispatcher/Router?
phalcon loader dispatcher
I am learning Phalcon (php).
This is an example from github using phalcon with the following folder structure
single-namespaces/
├── apps
│ ├── controllers
│ │ ├── IndexController.php
│ │ └── ProductsController.php
│ ├── models
│ │ └── Products.php
│ └── views
│ └── products
│ └── index.phtml
└── public
└── index.php
in public/index.php, $loader registered namesapces
$loader->registerNamespaces(
[
'SingleControllers' => '../apps/controllers/',
'SingleModels' => '../apps/models/'
]
);
$dispatcher also set the namespace
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('SingleControllers\');
return $dispatcher;
});
If I remove $dispatcher->setDefaultNamespace('SingleControllers\')
, error saying IndexController handler class cannot be loaded
Is that mean when loading the classes in namespaces, Dispatcher/Router will ignore the setting of loader? We must explicitly state the namespace for Dispatcher/Router?
phalcon loader dispatcher
phalcon loader dispatcher
asked Nov 29 '18 at 6:38
HKITHKIT
296
296
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Perhaps you misunderstood purpose of Loader and usage of namespaces.
When passing values to $loader->registerNamespaces(...)
you telling the framework where to look for your classes, in our case by calling SingleControllersIndexController
loader would try to include ../apps/controllers/IndexController.php
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to callSingleControllersIndexController::indexAction
then loader would try to include../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include..SimpleControllersIndexController.php
which does not exists under current folder.
– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533192%2fphalconn-dispatcher-and-loader-registernamespaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Perhaps you misunderstood purpose of Loader and usage of namespaces.
When passing values to $loader->registerNamespaces(...)
you telling the framework where to look for your classes, in our case by calling SingleControllersIndexController
loader would try to include ../apps/controllers/IndexController.php
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to callSingleControllersIndexController::indexAction
then loader would try to include../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include..SimpleControllersIndexController.php
which does not exists under current folder.
– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
add a comment |
Perhaps you misunderstood purpose of Loader and usage of namespaces.
When passing values to $loader->registerNamespaces(...)
you telling the framework where to look for your classes, in our case by calling SingleControllersIndexController
loader would try to include ../apps/controllers/IndexController.php
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to callSingleControllersIndexController::indexAction
then loader would try to include../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include..SimpleControllersIndexController.php
which does not exists under current folder.
– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
add a comment |
Perhaps you misunderstood purpose of Loader and usage of namespaces.
When passing values to $loader->registerNamespaces(...)
you telling the framework where to look for your classes, in our case by calling SingleControllersIndexController
loader would try to include ../apps/controllers/IndexController.php
Perhaps you misunderstood purpose of Loader and usage of namespaces.
When passing values to $loader->registerNamespaces(...)
you telling the framework where to look for your classes, in our case by calling SingleControllersIndexController
loader would try to include ../apps/controllers/IndexController.php
answered Nov 30 '18 at 13:25
NazariyNazariy
4,20833059
4,20833059
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to callSingleControllersIndexController::indexAction
then loader would try to include../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include..SimpleControllersIndexController.php
which does not exists under current folder.
– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
add a comment |
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to callSingleControllersIndexController::indexAction
then loader would try to include../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include..SimpleControllersIndexController.php
which does not exists under current folder.
– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Then whats the purpose of $dispatcher->setDefaultNamespace? Aren’t they both telling the framework when to look for the classes? @Nazariy
– HKIT
Nov 30 '18 at 13:32
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to call
SingleControllersIndexController::indexAction
then loader would try to include ../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Not quite, dispatcher has nothing to do with class autoloader, when dispatcher is is triggered with empty route it would try to use defaultNamespace, defaultController and defaultAction. So it would try to call
SingleControllersIndexController::indexAction
then loader would try to include ../apps/controllers/IndexController.php
– Nazariy
Nov 30 '18 at 13:54
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
Thank for the quick response. But if the dispatcher will include IndexController.php with empty route, why it will show error ‘IndexController handler class not found’?
– HKIT
Nov 30 '18 at 14:03
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include
..SimpleControllersIndexController.php
which does not exists under current folder.– Nazariy
Nov 30 '18 at 14:26
As I understood you have removed mapping for SingleControllers namespace, therefore you getting an error. It happens because autoloader doesn't know where to search for SingleControllersIndexController class. I assume according to PSR-4 autoloader in this scenario would try to include
..SimpleControllersIndexController.php
which does not exists under current folder.– Nazariy
Nov 30 '18 at 14:26
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
So if I create the following directory single-namespaces/Single/Controllers/IndexController.php, the file can be loaded?
– HKIT
Nov 30 '18 at 15:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53533192%2fphalconn-dispatcher-and-loader-registernamespaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown