Codeigniter 扩展控制器,未找到控制器

2023-10-12php开发问题
9

本文介绍了Codeigniter 扩展控制器,未找到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 Codeigniter 2.1.2 中,我想创建基本控制器,然后从该控制器扩展.它不起作用,我不知道为什么,我现在非常绝望.

In Codeigniter 2.1.2 I want to create base controller and then extends from this controller. It does not work and I have no idea why and I'm pretty desperate now.

applicationcoreMY_Base_Controller.php 我有这个:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Base_Controller extends CI_Controller 
{
    function __construct()
    {
        parent::__construct();
...

applicationcontrollersHome.php 我有这个:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Home extends MY_Base_Controller {

错误信息是

致命错误:在第 3 行的 ...applicationcontrollersHome.php 中找不到MY_Base_Controller"类

我不知道该怎么做,我在互联网上读到我必须将基本控制器放入核心文件夹,我必须将基本控制器命名为前缀 MY_,我做到了.但它仍然没有工作.在我的 config.php 中也是这一行

I have no idea what to do, I read all over the internet that I have to put base controller to core folder what I did, that I have to name base controller with prefix MY_, I did. But it is still no working. And in my config.php is this line as well

$config['subclass_prefix'] = 'MY_';

我使用 xampp 在本地主机上运行这个

Im running this on localhost using xampp

感谢您的帮助

编辑

有人可以下载以下链接试试看,然后告诉我出了什么问题.我刚刚下载了 codeigniter 试图创建基本控制器并扩展欢迎控制器.不工作.在下面的 rar 中只有修改过的文件.谢谢http://goo.gl/sKHkDl

Could someone please downlod following link try it, and tell me whats wrong. I have just downloaded codeigniter tried to create base controller and extend welcome controller. Not working. In following rar there are just modified files. Thank you http://goo.gl/sKHkDl

编辑 2

我可以通过将 MY_Base_Controller 重命名为 MY_Controller 来使其工作.这是否意味着,我只能为控制器创建一个扩展类?例如.我不能有

I'm able to get this working by renaming MY_Base_Controller to MY_Controller. Does this mean, I'm able to create only one extended class for a controller ? eg. I can not have

  • MY_Base_Auth_Controller
  • MY_Base_Article_Controller

只有MY_Controller?

推荐答案

我遇到了同样的问题,但如果我在 MY_Controller.php 文件中创建所有控制器都运行良好.

I had the same problem, but if I created all controllers in the MY_Controller.php file all worked well.

<?php

class MY_Controller extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        // do some stuff
    }
}

class MY_Auth_Controller extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
        // check if logged_in
   }
}

这篇关于Codeigniter 扩展控制器,未找到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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