gpt4 book ai didi

zend-framework - Zend Framework - 扩展模块 Controller

转载 作者:行者123 更新时间:2023-12-04 04:26:48 35 4
gpt4 key购买 nike

我有以下目录结构:

modules/
api/
controllers/
ApiController.php
InventoryController.php
OtherController.php

init() 方法在多个 Controller 中很常见,因此我想将其重构为父 Controller 类,例如:
class Api_ApiController extends Zend_Controller_Action
{
public function init()
{
// common code
}
}

当我尝试:
class Api_InventoryController extends Api_ApiController

我得到:

Fatal error: Class 'Api_ApiController' not found in /application/modules/api/controllers/InventoryController.php on line 4



为什么 Zend Framework 不将 Api_ApiController 映射到 modules/api/controllers/ApiController.php?

我已经通过将 ApiController 放在 library/中并注册命名空间来解决这个问题,但这对我来说似乎是一个 hack。

最佳答案

“问题”是,ZF 没有在自动加载器中注册 Controller 目录,因为 Controller 通常是通过 Zend_Controller_Dispatcher 加载的。 . Zend_Application_Module_Autoloader ,另一方面,它在 Bootstrap 中实例化,仅寄存器

        'dbtable' => array(
'namespace' => 'Model_DbTable',
'path' => 'models/DbTable',
),
'mappers' => array(
'namespace' => 'Model_Mapper',
'path' => 'models/mappers',
),
'form' => array(
'namespace' => 'Form',
'path' => 'forms',
),
'model' => array(
'namespace' => 'Model',
'path' => 'models',
),
'plugin' => array(
'namespace' => 'Plugin',
'path' => 'plugins',
),
'service' => array(
'namespace' => 'Service',
'path' => 'services',
),
'viewhelper' => array(
'namespace' => 'View_Helper',
'path' => 'views/helpers',
),
'viewfilter' => array(
'namespace' => 'View_Filter',
'path' => 'views/filters',
)

因此,您可以将基本 Controller 脚本包含在 require_once 中。或者你修改你的自动加载器以包括 Controller 目录。

关于zend-framework - Zend Framework - 扩展模块 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2922803/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com