[英]Phalcon: Inheritance of controllers with modules and common controllers
我希望有人能够为我提供帮助,因为我一直在疯狂尝试将其付诸实践。 我已经在网上进行了无数搜索,找到了一些信息,但是不幸的是,我似乎无法找到解决方案。
我正在尝试使用多个模块在Phalcon中实现以下目标。
MasterController扩展控制器
BackendController扩展了MasterController
ModuleController扩展了BackendController
ClientsController扩展了ModuleController
我的文件夹结构是这样的:
应用
| - > CRM
| - >控制器
| ---> ModuleController
| ---> ClientsController
共同
| - >控制器
| - > MasterController
| - > BackendController
现在,在CRM下我的Modules.php文件中,我具有以下内容:
$loader->registerNamespaces(
array(
'Multiple\Crm\Controllers' => __DIR__ . '/controllers/',
'Multiple\Crm\Models' => __DIR__ . '/models/',
'Multiple\Crm\Plugins' => __DIR__ . '/plugins/',
'Multiple\Common\Controllers' => __DIR__ . '/../../common/controllers/'
)
);
我的ModuleController文件如下所示:
class ModuleController extends Multiple\Common\Controllers\BackendBase
{
public function onConstruct()
{
echo "hello";
}
}
每当我运行代码时,我都会遇到以下致命错误:
致命错误:在第8行的/var/www/phalcon/html/apps/crm/controllers/ModuleController.php中找不到类'Mulitple \\ Common \\ Controllers \\ BackendBase'
我尝试了很多事情,但似乎无法使它起作用。 谁能对此有所了解,并告诉我我做错了什么?
提前谢谢了。
在审查@cvsguimaraes和@NikolaosDimoploulos的评论后,我选择了“再次开始”。 我使用了phalcon devtools通过apps选项生成了结构的基础。
基于此,我便能够从那里“构建”结构。
为了拥有继承权,我得到的最终结果是:
#File: apps/crm/controllers/ClientsController.php
namespace myApp\CRM\Controllers
class ClientsController extends ControllerBase {...}
#File: apps/crm/controllers/ControllerBase.php
namespace myApp\CRM\Controllers
class ControllerBase extends \myApp\common\Controllers\FrontendBase {...}
#File: common/controllers/FrontendBase.php
namespace myApp\common\Controllers
class FrontendBase extends \myApp\common\Controllers\MasterBase {...}
#File: common/controllers/MasterBase.php
namespace myApp\common\Controllers
class MasterBase extends \Phalcon\Mvc\Controller {...}
然后在文件:apps / crm / Module.php中,我具有以下内容:
namespace myApp\CRM;
class Module implements ModuleDefinitionInterface
{
public function registerAutoloaders()
{
$loader = new Loader();
$loader->registerNamespaces(array(
'myApp\CRM\Controllers' => __DIR__ . '/controllers',
'myApp\CRM\Models' => __DIR__ . '/models',
'myApp\common\Controllers' => __DIR__ . '/../../common/Controllers',
'myApp\common\Models' => __DIR__ . '/../../common/Models'
));
$loader->register();
}
}
然后,这将按您期望的那样工作。 您可以在MasterBase中具有可以从更高级别调用的函数,还可以运行诸如在不同级别的输出中添加css和JS之类的函数,从而使您可以根据需要分离控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.