Welcome Guest, Not a member yet? Register   Sign In
learning codeigniter - Fatal error: Class blog: Cannot inherit from undefined class controller
#1

[eluser]Unknown[/eluser]
Hi,

I am new to codeigniter, i am getting this error to run simple codeigniter example.

Fatal error: Class blog: Cannot inherit from undefined class controller in C:\ns\www\ci\system\application\controllers\blog.php on line 2

right now I just want to use blog.php class
<?php
class Blog extends Controller {
function index()
{
echo 'Hello World!';
}
}
?>
and i have index.php file
<? require("../system/application/controllers/blog.php"); ?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>

I will be thankful if someone help me.

Thanks

HF
#2

[eluser]Michael Wales[/eluser]
You should be using the index.php file that came with CodeIgniter.
#3

[eluser]Unknown[/eluser]
[quote author="walesmd" date="1189820334"]You should be using the index.php file that came with CodeIgniter.[/quote]

Thanks, i got it.
#4

[eluser]esra[/eluser]
You do not have a constructor method in your Blog class. For PHP4, the constructor's method name would be Blog as shown below. For PHP5, the constructor's method name would be __construct(). The constructor method of the parent class must be called in the constructor. The Index() function includes the private portion of the constructor which is only used within that class. By comparison, the code in the constructor (i.e., the Blog or __construct method) can be inheirited by any controller subclassed (extended) from the Blog class.

Code:
<?php
class Blog extends Controller
{
    function Blog()
    {
        parent::Controller();    
    }

    function index()
    {
        echo 'Hello World!';
    }
}
?>




Theme © iAndrew 2016 - Forum software by © MyBB