Codeigniter构造函数。有什么不同? [英] Codeigniter constructors. What is the difference?

查看:100
本文介绍了Codeigniter构造函数。有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CI中看到两种建构者。例如...

  class Blog extends CI_Controller 
{
function __construct()
{
parent :: __ construct();
}
}

  class Blog extends CI_Controller 
{
function Blog()
{
parent :: Controller
}
}

它们之间有什么区别?我不知道选择哪个。

解决方案

如果你使用Codeigniter 2+(你应该是)...第二个选项不工作,因为它使用PHP4风格的构造函数调用。



实际上,第二个选项不会工作,因为php4构造函数调用需要匹配你扩展的类...



所以,使用第一个。它使用PHP5风格的构造函数调用。



对于更多有关PHP5构造函数的信息


I see two types of contructors in CI. For instance...

class Blog extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
}

and

class Blog extends CI_Controller
{
       function Blog()
       {
                parent::Controller();
       }
}

What is the difference between them? I'm not sure which to choose.

解决方案

If you are using Codeigniter 2+ (which you should be)... The second option will not work, as it uses the PHP4 style constructor calls.

Actually, the second option wouldn't work anyway because the php4 constructor call needs to match the class you're extending...

So yeah, use the first one. It uses PHP5 style constructor calls.

For more information on PHP5 constructors

这篇关于Codeigniter构造函数。有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆