phalcon架構多模組程式中 找不到非預設的模組

來源:互聯網
上載者:User
當我訪問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;
修改app/manage/Module.php

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());        };    }}

修改test/config/modules.php

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'    )        ));

test/config/services.php未修改

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;});

test/config/routes.php

get("router");foreach ($application->getModules() as $key => $module) {    $namespace = str_replace('Module','Controllers', $module["className"]);    $router->add('/'.$key.'/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 'index',        'action' => 'index',        'params' => 1    ))->setName($key);    $router->add('/'.$key.'/:controller/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 1,        'action' => 'index',        'params' => 2    ));    $router->add('/'.$key.'/:controller/:action/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 1,        'action' => 2,        'params' => 3    ));}

public/index.php

handle()->getContent();} catch (Exception $e) {    echo $e->getMessage();}

回複內容:

當我訪問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;
修改app/manage/Module.php

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());        };    }}

修改test/config/modules.php

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'    )        ));

test/config/services.php未修改

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;});

test/config/routes.php

get("router");foreach ($application->getModules() as $key => $module) {    $namespace = str_replace('Module','Controllers', $module["className"]);    $router->add('/'.$key.'/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 'index',        'action' => 'index',        'params' => 1    ))->setName($key);    $router->add('/'.$key.'/:controller/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 1,        'action' => 'index',        'params' => 2    ));    $router->add('/'.$key.'/:controller/:action/:params', array(        'namespace' => $namespace,        'module' => $key,        'controller' => 1,        'action' => 2,        'params' => 3    ));}

public/index.php

handle()->getContent();} catch (Exception $e) {    echo $e->getMessage();}

pbulic/index.php
require DIR . '/../config/routes.php';下面

加上$di->set('router',$router);

set('router',$router);    echo $application->handle()->getContent();} catch (Exception $e) {    echo $e->getMessage();}

題主給的資訊不夠,多模組設定裡有幾個比較重要的東西都不給出來,比如:routes.php 和 各個模組裡的 Module.php,這兩個都關係到多模組的載入。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.