0

I'm running CodeIgniter 2.1.3.

I've gone through posts such as but could not solve my problem:

Blank Screen with CodeIgniter

I've installed CodeIgniter under /var/www/ci/ and access it as http:// localhost/ci/

I've created the simple page application/controllers/helloworld.php

<?php
class HelloWorld extends Controller {
  function HelloWorld() {
  //function __construct() {
    //parent::__construct();
    parent::Controller();
  }
  function index() {
    echo "Hello, World!";
  }
}

but http:// localhost/ci/index.php/helloworld/

gives me a blank page. How can I fix this?

I've even tried changing config.php to contain

$config['base_url'] = 'http:// localhost/ci/';

(without the extra space in localhost ).

I've got mod_rewrite enabled, I've got mysqli php module enabled.

Where am I going wrong?

Thanks.

Community
  • 1
  • 1
Jason Posit
  • 1,255
  • 1
  • 16
  • 36

1 Answers1

2

In the 2.x.x versions of CodeIgniter the these classes are called like CI_Controller (every other system class is prefixed with CI_.

Try changing it like this:

class HelloWorld extends CI_Controller {
   // if you don't want to do anything in the __controller you don't have to
   // override it, so its omitted

   public function index() {
       echo "Hello, World!";
   }
}
complex857
  • 19,129
  • 6
  • 44
  • 50
  • I changed Controller to CI_Controller but also had to delete the constructor for it to work. Why was deleting the constructor necessary? Adding a CI_Controller or __construct constructor would not work. Why? Thanks. – Jason Posit Jul 08 '13 at 16:06
  • 1
    It's not necessary, but if you want to include it write it like `parent::__construct()`. Calling it by the class's name was deprecated with php5. In your case it would try to call an existing method (if you extend `CI_Controller` the method `Controller` is would be just some regular method). – complex857 Jul 08 '13 at 16:09
  • Quite right. function() __construct { parent::__construct(); } is the only constructor syntax which seems to work (no reference to CI_Controller or HelloWorld). Thanks. – Jason Posit Jul 08 '13 at 16:14
  • 1
    That's the proper way to [write a constructor in PHP 5+](http://php.net/manual/en/language.oop5.decon.php). Make it a habit ;) – Aken Roberts Jul 10 '13 at 08:10