当我访问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中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。

CSP重要因為它能防範XSS攻擊和限制資源加載,提升網站安全性。 1.CSP是HTTP響應頭的一部分,通過嚴格策略限制惡意行為。 2.基本用法是只允許從同源加載資源。 3.高級用法可設置更細粒度的策略,如允許特定域名加載腳本和样式。 4.使用Content-Security-Policy-Report-Only頭部可調試和優化CSP策略。

HTTP請求方法包括GET、POST、PUT和DELETE,分別用於獲取、提交、更新和刪除資源。 1.GET方法用於獲取資源,適用於讀取操作。 2.POST方法用於提交數據,常用於創建新資源。 3.PUT方法用於更新資源,適用於完整更新。 4.DELETE方法用於刪除資源,適用於刪除操作。

HTTPS是一種在HTTP基礎上增加安全層的協議,主要通過加密數據保護用戶隱私和數據安全。其工作原理包括TLS握手、證書驗證和加密通信。實現HTTPS時需注意證書管理、性能影響和混合內容問題。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版
中文版,非常好用

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。