CodeIgniter Forums
Is Controller Index are not recommended? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Is Controller Index are not recommended? (/showthread.php?tid=60938)



Is Controller Index are not recommended? - El Forum - 08-05-2014

[eluser]rahendz[/eluser]
I create controller like structure below :

Code:
controller
- app
-- index.php

and inside index.php i put controller class like below :

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Index extends CI_Controller {
public function index()
{
  echo "Here i am";
}
}
/* End of file index.php */
/* Location: ./application/controllers/zudan/index.php */

and i accessed using this url like below :

Code:
http://localhost/index.php/app/index

and it show that echoing twice like below :

Code:
Here i amHere i am

so what i'm gonna ask is Controller Class with Index as a Name of Class not recommended since it called twice? or i got something wrong? thanks before and sorry for my bad english.


Is Controller Index are not recommended? - El Forum - 08-05-2014

[eluser]Narf[/eluser]
That's a PHP limitation, or more specifically a BC feature for the PHP4 days. Having a method name that matches the class name makes it a constructor.


Is Controller Index are not recommended? - El Forum - 08-05-2014

[eluser]rahendz[/eluser]
[quote author="Narf" date="1407245413"]That's a PHP limitation, or more specifically a BC feature for the PHP4 days. Having a method name that matches the class name makes it a constructor.[/quote]

Ahh, i see. So that's why it called twice. thanks Narf.


Is Controller Index are not recommended? - El Forum - 08-07-2014

[eluser]Tpojka[/eluser]
[quote author="rahendz" date="1407254122"][quote author="Narf" date="1407245413"]That's a PHP limitation, or more specifically a BC feature for the PHP4 days. Having a method name that matches the class name makes it a constructor.[/quote]thanks Narf.[/quote]

+1