• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

phalcon框架多模块程序中 找不到非默认的模块

php 搞代码 3年前 (2022-01-25) 9次浏览 已收录 0个评论
文章目录[隐藏]

当我访问http://192.168.0.146/test/显示的是正常页面
当我访问http://192.168.0.146/test/manage
显示**Test\Frontend\Controllers\ManageController handler class cannot be loaded**
我需要执行Test\Manage\Controllers\IndexController 还需要如何处理?

项目创建过程如下

phalcon project test modules –enable-webtools
Phalcon DevTools (2.0.7)
Success: Controller “index” was successfully created.

Success: Project “test” was successfully created.

复制app/frontend-》app/manage
修改app/manage/controllers下程序的namespace 为Test\Manage\Controllers;
修改6本文来源gao@dai!ma.com搞$代^码!网7

搞gaodaima代码

app/manage/Module.php

<code class="php"><?phpnamespace Test\Manage;use Phalcon\DiInterface;use Phalcon\Loader;use Phalcon\Mvc\View;use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;use Phalcon\Mvc\ModuleDefinitionInterface;class Module implements ModuleDefinitionInterface{    /**     * Registers an autoloader related to the module     *     * @param DiInterface $di     */    public function registerAutoloaders(DiInterface $di = null)    {        $loader = new Loader();        $loader->registerNamespaces(array(            'Test\Manage\Controllers' => __DIR__ . '/controllers/',            'Test\Manage\Models' => __DIR__ . '/models/',        ));        $loader->register();    }    /**     * Registers services related to the module     *     * @param DiInterface $di     */    public function registerServices(DiInterface $di)    {        /**         * Read configuration         */        $config = include APP_PATH . "/apps/manage/config/config.php";        /**         * Setting up the view component         */        $di['view'] = function () {            $view = new View();            $view->setViewsDir(__DIR__ . '/views/');            return $view;        };        /**         * Database connection is created based in the parameters defined in the configuration file         */        $di['db'] = function () use ($config) {            return new DbAdapter($config->toArray());        };    }}</code>

修改test/config/modules.php

<code class="php"><?php/** * Register application modules */$application->registerModules(array(    'frontend' => array(        'className' => 'Test\Frontend\Module',        'path' => __DIR__ . '/../apps/frontend/Module.php'    ),    'manage' => array(        'className' => 'Test\Manage\Module',        'path' => __DIR__ . '/../apps/manage/Module.php'    )        ));</code>

test/config/services.php未修改

<code class="php"><?php/** * Services are globally registered in this file * * @var \Phalcon\Config $config */use Phalcon\Mvc\Router;use Phalcon\Mvc\Url as UrlResolver;use Phalcon\Di\FactoryDefault;use Phalcon\Session\Adapter\Files as SessionAdapter;use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;use Phalcon\Mvc\View;use Phalcon\Mvc\View\Engine\Volt as VoltEngine;/** * The FactoryDefault Dependency Injector automatically registers the right services to provide a full stack framework */$di = new FactoryDefault();/** * Registering a router */$di->set('router', function () {    $router = new Router();    $router->setDefaultModule('frontend');    $router->setDefaultNamespace('Test\Frontend\Controllers');    return $router;});/** * The URL component is used to generate all kinds of URLs in the application */$di->set('url', function () {    $url = new UrlResolver();    $url->setBaseUri('/test/');    return $url;});/** * Setting up the view component */$di->setShared('view', function () use ($config) {    $view = new View();    $view->setViewsDir($config->application->viewsDir);    $view->registerEngines(array(        '.volt' => function ($view, $di) use ($config) {            $volt = new VoltEngine($view, $di);            $volt->setOptions(array(                'compiledPath' => $config->application->cacheDir,                'compiledSeparator' => '_'            ));            return $volt;        },        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'    ));    return $view;});/** * Database connection is created based in the parameters defined in the configuration file */$di->set('db', function () use ($config) {    return new DbAdapter($config->database->toArray());});/** * If the configuration specify the use of metadata adapter use it or use memory otherwise */$di->set('modelsMetadata', function () {    return new MetaDataAdapter();});/** * Starts the session the first time some component requests the session service */$di->setShared('session', function () {    $session = new SessionAdapter();    $session->start();    return $session;});/*** Set the default namespace for dispatcher*/$di->setShared('dispatcher', function() use ($di) {    $dispatcher = new Phalcon\Mvc\Dispatcher();    $dispatcher->setDefaultNamespace('Test\Frontend\Controllers');    return $dispatcher;});</code>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:phalcon框架多模块程序中 找不到非默认的模块
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址