• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
classNames and __construct

#1
[eluser]Richard Testani[/eluser]
I'm trying to figure out what the differences are in the 2 versions.
In the following, I've set:
$route['default_controller'] = "index";


I know in php4 you use the class name as the construct and in php5 you'd use __construct().
I'm running php5, so it's __construct() for me, yet...
Code:
class Index extends Controller {

public function __construct() {
  parent::Controller();
  $this->load->database();

  $bsn_data['mode'] = 'test';
  $this->load->model('Bsn');
}
}

Returns file not found. status 404.
I'm not sure why.
Once I add the following to the Index class it works:
Code:
public function Index() {

}
I can't figure out the why's on this one.

#2
[eluser]Dam1an[/eluser]
Will naming a controller index not cause a problem as it's the default function... which in this case would also be the constructor?

#3
[eluser]Richard Testani[/eluser]
Good question, I hadn't thought about it that way - is Index a reserved name?.
I'll test it out with a different name.

Thanks

#4
[eluser]Dam1an[/eluser]
It appears so, reserved names


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.