【问题标题】:Class Not Found when extends a Class of Subdirectory Controller in ZendFramework在 ZendFramework 中扩展子目录控制器类时未找到类
【发布时间】:2012-09-11 11:58:13
【问题描述】:

我有下一个结构

-应用程序
--控制器
---子
----DemoController.php
---索引控制器.php
-楷模
- 意见
-Boostrap.php

好吧,在我的 Sub/DemoController.php 我有下一个:

<?php
class Sub_DemoController extends Zend_Controller_Action
{
    public function indexAction()
    {
        echo 'hello demo';
    }
}

我的 IndexController.php 是这样的:

<?php
class IndexController extends Sub_DemoController
{
}

当我运行我的 web 时,会抛出下一个错误:找不到 Class 'Sub_DemoController' ... 我尝试使用 Application_Sub_DemoController 初始化类,但返回相同的结果。

我不想使用模块,我知道如何在 Zend Framewoork 中使用模块,但我不去寻找它。

有什么想法吗?

【问题讨论】:

    标签: php model-view-controller zend-framework controller


    【解决方案1】:

    请看Zend framework (1.7.5): how to change controller directory

    我认为您没有正确设置控制器目录,或者您的自动加载器无法正常工作。

    【讨论】:

    • 我不想在这种情况下使用模块,如果我使用 demo.dev/sub_demo 它可以工作,我认为也许我需要在我的 Bootstrap 或类似的配置中进行某种类型的配置
    【解决方案2】:

    您需要将resourceType 添加到您的资源自动加载器中,并将其添加到您的引导文件中:

    $this->getResourceLoader()
         ->addResourceType('sub', 'controllers/Sub', 'Sub');
    

    更多:http://framework.zend.com/manual/1.12/en/zend.loader.autoloader-resource.html

    【讨论】:

    • 我已经覆盖了自动加载器类,但这是我正在寻找的解决方案,谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-01-10
    • 2015-07-19
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2013-04-03
    相关资源
    最近更新 更多