php多模块目录结构,phalconphp中的多模块MVC结构

嗨,我正在尝试为前端和后端实现多模块MVC,就像phalconphp documentations中那样.但我无法使其工作.大约一个小时但我真的无法理解问题出在哪里.

任何人都可以指导我如何为前端和后端的多模块mvc制作骨架.

我应该把Moudle.php放在前端和后端

还有什么我应该放在public / index.php中的bootstrap文件中

以及我需要的任何额外文件或信息.

解决方法:

更具体地说,您将对以下内容感兴趣:

我倾向于在index.php中使用它:

$application = new \Phalcon\Mvc\Application($di);

// Register the installed modules

$application->registerModules(

array(

'web' => array(

'className' => 'Apps\Web\Module',

'path' => '../apps/web/Module.php',

)

)

);

echo $application->handle()->getContent();

在我的Module.php中:

namespace Apps\Web;

use Phalcon\Loader;

use Phalcon\Mvc\Dispatcher;

use Phalcon\Mvc\View;

use Phalcon\Mvc\ModuleDefinitionInterface;

class Module implements ModuleDefinitionInterface

{

/**

* Register a specific autoloader for the module

*/

public function registerAutoloaders()

{

$loader = new Loader();

$loader->registerNamespaces(

array(

'Apps\Web\Controllers' => '../apps/web/controllers/',

)

);

$loader->register();

}

/**

* Register specific services for the module

* @param \Phalcon\DI\FactoryDefault $di

*/

public function registerServices($di)

{

//Registering a dispatcher

$di->set(

'dispatcher',

function() use ($di) {

$eventsManager = $di->getShared('eventsManager');

$dispatcher = new Dispatcher();

$dispatcher->setDefaultNamespace('Apps\Web\Controllers');

$eventsManager->attach(

'dispatch:beforeException',

function($event, $dispatcher, $exception) use ($di) {

/* @var $dispatcher \Phalcon\Mvc\Dispatcher */

switch ($exception->getCode()) {

case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:

case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:

$di->set('lastException', $exception);

$dispatcher->forward(

array(

'module' => 'web',

'controller' => 'error',

'action' => 'notFound',

)

);

return false;

default:

$di->set('lastException', $exception);

$dispatcher->forward(

array(

'module' => 'web',

'controller' => 'error',

'action' => 'uncaughtException',

)

);

return false;

}

}

);

$dispatcher->setEventsManager($eventsManager);

return $dispatcher;

}

);

}

}

希望这有帮助!

标签:php,phalcon

来源: https://codeday.me/bug/20190612/1225706.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值