Welcome Guest, Not a member yet? Register   Sign In
新建控制器出错了“A PHP Error was encountered”
#1

[eluser]Unknown[/eluser]
Code:
class Index extends CI_Controller {

    public function index()
    {
        $this->load->view('welcome_message');
    }
}


A PHP Error was encountered
Severity: Notice

Message: Undefined property: Index::$load

Filename: controllers/index.php

Line Number: 7


Fatal error: Call to a member function view() on a non-object in E:\AppServ\www\CodeIgniter\application\controllers\index.php on line 7

配置文件修改:$route['default_controller'] = "index";
地址是:http://www.qqsb.us/codeigniter/index.php/index/index/
#2

[eluser]osci[/eluser]
User Guide - Reserved Names
#3

[eluser]Basketcasesoftware[/eluser]
Ummm. PHP is case sensitive. He named his class "Index" not "index"
#4

[eluser]osci[/eluser]
[quote author="Basketcasesoftware" date="1308826981"]Ummm. PHP is case sensitive. He named his class "Index" not "index"[/quote]

Still, according to the user_guide this is a reserved word.

EDIT:
And according to "ci code syntax" class is first letter capitalized, isn't it?
#5

[eluser]Basketcasesoftware[/eluser]
the user guide uses the lower case specifically on that instance of a reserved word. The others are capitalized. That's not accidental. To PHP "class index" is not the same as "class Index". This might be an error in the manual. Wouldn't be the first time. Smile
#6

[eluser]InsiteFX[/eluser]
Since your controller classes will extend the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise your local functions will override them. The following is a list of reserved names. Do not name your controller any of these:

Controller
CI_Base
_ci_initialize
Default
index

You guys need to read the system/core/loader.php and CodeIgniter.php file to really understand what is going on in the background!

CodeIgniter doe's a lot of upper and lower case converting on the fly!

InsiteFX
#7

[eluser]Basketcasesoftware[/eluser]
@InsiteFX - That's an understatement if I ever heard one. A detail that probably should be noted in that section of the manual.




Theme © iAndrew 2016 - Forum software by © MyBB