当我访问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
<?php namespace 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()); }; } }
修改test/config/modules.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' ) ));
test/config/services.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; });
test/config/routes.php
<?php $router = $di->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
<?php use Phalcon\Mvc\Application; error_reporting(E_ALL); define('APP_PATH', realpath('..')); try { /** * Read the configuration */ $config = include APP_PATH . "/apps/frontend/config/config.php"; /** * Include services */ require __DIR__ . '/../config/services.php'; /** * Handle the request */ $application = new Application($di); /** * Include modules */ require __DIR__ . '/../config/modules.php'; /** * Include routes */ require __DIR__ . '/../config/routes.php'; echo $application->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
<?php namespace 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()); }; } }
修改test/config/modules.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' ) ));
test/config/services.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; });
test/config/routes.php
<?php $router = $di->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
<?php use Phalcon\Mvc\Application; error_reporting(E_ALL); define('APP_PATH', realpath('..')); try { /** * Read the configuration */ $config = include APP_PATH . "/apps/frontend/config/config.php"; /** * Include services */ require __DIR__ . '/../config/services.php'; /** * Handle the request */ $application = new Application($di); /** * Include modules */ require __DIR__ . '/../config/modules.php'; /** * Include routes */ require __DIR__ . '/../config/routes.php'; echo $application->handle()->getContent(); } catch (Exception $e) { echo $e->getMessage(); }
pbulic/index.php
require DIR . '/../config/routes.php';下面
加上$di->set('router',$router);
<?php use Phalcon\Mvc\Application; error_reporting(E_ALL); define('APP_PATH', realpath('..')); try { /** * Read the configuration */ $config = include APP_PATH . "/apps/manage/config/config.php"; /** * Include services */ require __DIR__ . '/../config/services.php'; /** * Handle the request */ $application = new Application($di); /** * Include modules */ require __DIR__ . '/../config/modules.php'; /** * Include routes */ require __DIR__ . '/../config/routes.php'; $di->set('router',$router); echo $application->handle()->getContent(); } catch (Exception $e) { echo $e->getMessage(); }
题主给的信息不够,多模块设置里有几个比较重要的东西都不给出来,比如:routes.php 和 各个模块里的 Module.php,这两个都关系到多模块的加载。

PHP作为一种开放源码的脚本语言,它具有可移植性、跨平台、代码简洁易读、开发速度快、扩展性强等特点而被广泛使用。在PHP中,使用框架可以更加方便地组织代码、提高代码质量和开发效率。Phalcon5是PHP中一个较为优秀的框架,本文将介绍如何使用Phalcon5框架进行Web开发。一、安装Phalcon5框架在开始使用Phalcon5框架之前,需要先进行安装。

如何在Phalcon框架中使用数据库事务(Transactions)引言:数据库事务是一种重要的机制,可以确保数据库操作的原子性和一致性。在使用Phalcon框架进行开发时,我们也经常需要使用数据库事务来处理一系列相关的数据库操作。本文将介绍如何在Phalcon框架中使用数据库事务,并提供相关的代码示例。一、什么是数据库事务(Transactions)?数据

如何利用PHP-FPM优化提高Phalcon应用的性能导语:Phalcon是一个高性能的PHP框架,结合PHP-FPM可以进一步提高应用的性能。本文将介绍如何利用PHP-FPM优化Phalcon应用的性能,并提供具体的代码示例。一、什么是PHP-FPMPHP-FPM(PHPFastCGIProcessManager)是一个独立于Web服务器的PHP进程

随着互联网的不断发展,Web应用开发已经成为各行各业不可或缺的一部分。而PHP作为一种流行的服务器脚本语言,也成为了Web应用开发的主流语言之一。然而,PHP语言自身的性能和扩展性等方面问题也不可避免地限制了其在Web开发领域的发展。为了解决这些问题,Phalcon作为一种新的PHP框架应运而生,致力于提供一个高性能、易于扩展、易用且可靠的

随着Web应用程序的不断发展,相应的Web开发框架也不断涌现。其中Phalcon框架因其高性能和灵活性受到了越来越多开发者的青睐。Phalcon框架提供了许多有用的组件,其中ORM(对象关系映射)被认为是最为重要的之一。本文将介绍如何在Phalcon框架中使用ORM以及一些实际应用示例。什么是ORM首先,我们需要了解什么是ORM。ORM是Object-Rel

在当前信息时代,大数据、人工智能、云计算等技术已经成为了各大企业关注的热点。在这些技术中,显卡渲染技术作为一种高性能图形处理技术,受到了越来越多的关注。显卡渲染技术被广泛应用于游戏开发、影视特效、工程建模等领域。而对于开发者来说,选择一个适合自己项目的框架,是一个非常重要的决策。在当前的语言中,PHP是一种颇具活力的语言,一些优秀的PHP框架如Yii2、Ph

随着社交媒体应用的不断增长,越来越多的开发人员开始关注哪个框架最适合用来构建这样的应用。Symfony和Phalcon是两个非常受欢迎的PHP框架,它们都有着成熟的社区和强大的开发工具。但是如果你需要开发大规模的社交媒体应用程序,那么哪个框架更适合呢?Symfony是一个成熟的PHP框架,它提供了丰富的功能和工具,可以帮助你快速构建大型应用程序。Symfon

对于初学者来说,选择微框架时,Slim更易于安装和配置,而Phalcon提供了更全面的配置,包括ORM和CLI工具。Slim具有灵活的正则表达式路由系统,而Phalcon使用基于注解的路由,提供自动路由和对RESTfulURL的支持。在持久性方面,Slim需要第三方库,而Phalcon集成了VoltaORM。在CLI工具方面,Slim没有内置工具,而Phalcon提供了用于创建代码骨架的“phalcon”工具。选择最适合的框架取决于项目需求,对于初学者,Slim的简洁性可能是一个优势,而对于需要


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
