这个Codeigniter代码是否正确? [英] Is this Codeigniter code correct?

查看:94
本文介绍了这个Codeigniter代码是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始看着PHP框架,花费了大量的时间从头开始做一切。我认为我会给予Codeigniter一个朋友推荐给我。

I've just started looking at PHP Frameworks after spending loads of wasted time doing everything from scratch. I thought I would give Codeigniter a go after a friend recommended it to me.

我完成了第一个教程,没有问题,但我遇到了第二个。

I worked through the first tutorial and there were no issues but I'm getting stuck with the second one.

起初,我的代码与教程完全相同:

At first my code was identical to the tutorial:

<?php


class Blog extends CI_Controller{


    function Blog()
    {

        parent::CI_Controller();

        $this->load->scaffolding('entries');
    }


    public function index(){

        $data['title'] = "My Blog Title";
        $data['heading'] = "An intresting title";


        $data['todo'] = array('create media player','design site','finish project');

        $this->load->view('blog_view',$data);
    }
}

?>

但我有一个内部服务器错误。看了用户指南后,它显示了使用构造函数的不同方法。

But I got an internal server error. After looking at the user guide it shows a different way for using the constructor.

我将代码更改为文档规范。

I changed the code to the document spec.

<?php


class Blog extends CI_Controller{


    public function __construct() {

        parent::__construct();

        $this->load->scaffolding('entries');
    }




    public function index(){

        $data['title'] = "My Blog Title";
        $data['heading'] = "An intresting title";


        $data['todo'] = array('create media player','design site','finish project');

        $this->load->view('blog_view',$data);
    }
}

?>

但我仍然得到一个内部错误。我不知道我的代码是否错误或我错误配置了别的东西。一些建议是好的,谢谢。

But I still get an internal error. I don't know if my code is wrong or I misconfigured something else. Some advice would be good, thanks.

编辑:
为了说明 - 当我向类添加构造函数时,我只得到一个内部错误。

To clarify - I only get an internal error when I add the constructor to the class.

推荐答案

这很可能是因为您尝试加载 scaffolding

This will most likely because you're trying to load scaffolding in the latest version of CodeIgniter.

脚手架已被贬值。在2.0中 已删除 ,现在的最新版本2.0.2

Scaffolding has been depreciated since version 1.6. It was removed in 2.0, and the latest version is now 2.0.2

关于使用哪个提供的代码段,后一种形式的声明构造函数( __ construct )优于使用类名( Blog )。这个方法自2.0以来也与CodeIgniter的核心类一致。

In terms of which of your provided snippets to use, the latter form of declaring a constructor (__construct) is preferred over using the Class name (Blog). This method is also consistent with the Core Classes of CodeIgniter since 2.0.

另外,我不知道为什么CodeIgniter包括这样的过时的示例在他们的教程。 EllisLab似乎最近对CI项目失去了兴趣,这是一个耻辱:(

As an aside, I've got no idea why CodeIgniter are including such out-of-date samples in their tutorials. EllisLab's seem to have lost total interest in the CI project recently, which is a shame :(

这篇关于这个Codeigniter代码是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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