在 Zend 中使用 BaseController 扩展 IndexController

2023-10-11php开发问题
0

本文介绍了在 Zend 中使用 BaseController 扩展 IndexController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用全局基本控制器来扩展我的控制器:

I'm trying to extend my controllers with a global base controller as such:

class BaseController extends Zend_Controller_Action {
 // common controller actions
    public function listAction() {
        // do stuff
    }
}

class IndexController extends BaseController {
 // index controller specific actions
}

class LoginController extends BaseController {
 // login controller specific actions
}

但我收到此错误:PHP 致命错误:在第 3 行的/var/www/Zend/project/application/controllers/IndexController.php 中找不到类BaseController"

But I get this error: PHP Fatal error: Class 'BaseController' not found in /var/www/Zend/project/application/controllers/IndexController.php on line 3

关于如何让 Zend看到"这个控制器的任何想法?

Any ideas on how to get Zend to "see" this controller?

推荐答案

Autoloader

设置自动加载器并使用自动加载器注册除了 Zend 库之外的库(在设置包含路径后在 bootstrap.php 中):

Autoloader

Setup the autoloader and register your library which should be besides the Zend library with the autoloader like so (in your bootstrap.php after setting the include path):

//AutoLoad loads classes automatically if they are used
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Mylibrary_');

Zend 命名约定

那么你应该按如下方式重命名你的 BaseController

Zend naming conventions

Then you should rename your BaseController as follows

/Zend (folder)
/Mylibrary (folder)
    /Controller (folder)
        Action.php <-- this is your basecontroller file

其中包含:

class Mylibrary_Controller_Action extends Zend_Controller_Action
{
}

和控制器文件夹中的普通控制器:

and your normal controllers in the controller folder:

class IndexController extends Mylibrary_Controller_Action
{
}

所以基本上当你想扩展框架时,你可以在自己的库中保留一个并行结构.

so basically when you want to extend the framework you keep a parallel structure in your own library.

这篇关于在 Zend 中使用 BaseController 扩展 IndexController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17