English 中文(简体)
编码协调器:推广共同控制器
原标题:codeigniter: extending common controller

我宣读我在这个问题上发现的所有立场,但没有任何结果。 I m, using Codeigniter 2.02 in a LAMP with Papa2.2 and PHP5.3.2

我试图建立一个共同的控制人,我的共同控制者将继承这一控制者,这样我就可以在那里履行共同的任务。

我有:

file: parent_controller.php

if ( ! defined( BASEPATH )) exit( No direct script access allowed );

class Parent_controller extends CI_Controller {

    public function Parent_controller()
    {
        parent::__construct();
    }

    public function index() {
        echo "Hi!";
    }
}

file: welcome.php

if ( ! defined( BASEPATH )) exit( No direct script access allowed );

class Welcome extends Parent_controller {

    public function __construct()
    {
        parent::__construct();
    }
}

我曾尝试过我所找到的下一个解决办法,但其中没有一个正在发挥作用:

  • 公共职能 __contstruct( 而不是 公职 父母_ Controller()

  • 父母:

  • put the parent_controller.php file into core

  • 将母子——控制器.php的档案输入 Controllers

  • 在汇合/汇合处增加:

    function __autoload($class){
            if (file_exists(APPPATH."(controllers|core)/".$class.EXT)){
                 require_once(APPPATH. (controllers|core)/ .$class.EXT);
           }
    }
    

谢谢大家。

最佳回答

• 从Pitro StIHR那里寻找这个职位:

http://philstovski.co.uk/blog/201002/CodeIgniter-Base-Classes-Keeping-it-DRY

钥匙是使用其职务中所解释的本土自动载荷:

/*
| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
| 
| Nothing to do with cnfig/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
*/
function __autoload($class)
{
    if(strpos($class,  CI_ ) !== 0)
    {
        @include_once( APPPATH .  core/ . $class . EXT );
    }
}

NOTE

请注意,您希望在<条码>核心上把所有“基地”控制器放在CI2+的夹中。

问题回答

This bit is correct

public function __contstruct() instead of public function Parent_controller()

但是,你们重新寻找的是千年预案。 因此,如果你在文件/申请/图书馆/文件夹中设立控制员,将文件MY_Controller.php和MY_Controller编成文件,就会工作。

你们也可以改变“青年”的序号,以适应你们在集会上的一切。 php档案。 展望:

/*
|--------------------------------------------------------------------------
| Class Extension Prefix
|--------------------------------------------------------------------------
|
| This item allows you to set the filename/classname prefix when extending
| native libraries.  For more information please see the user guide:
|
| http://codeigniter.com/user_guide/general/core_classes.html
| http://codeigniter.com/user_guide/general/creating_libraries.html
|
*/
$config[ subclass_prefix ] =  MY_ ;

For further reading and a more depth explanation see http://codeigniter.com/user_guide/general/core_classes.html

还指出,它没有装载大量档案。 它只看着一名叫MY_Controller.php的管理人员。

如果你想的话,它将装满负荷。 MY_Release_Controller.php和MY_Web_Controller.php,它赢得了t。

If you can include multiple controllers in that one file, or include other files from that file.

当然,你可以在此基础上继续努力,但可以了解更多信息。





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

CodeIgniter adding semicolons

How do I stop CodeIgniter adding semicolons ; to data sent via POST that contains ampersand &? For example it is converting "a=1&b=2&c=3" into "a=1&b;=2&c;=3". From looking on the forums ...

Best way to make Admin pages in CodeIgniter?

I m working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I m wondering what would be the better way to put these into an MVC structure. ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签