2 requests in controller |
[eluser]Unknown[/eluser]
Hi, i am a new user from CI and in my first controller i look this: Code: <?php the resulte is: hihi This is normal? And about performance?
[eluser]Aken[/eluser]
Don't name your controller Index, or the index() method will act as a constructor. http://www.php.net/manual/en/language.oop5.decon.php
[eluser]CroNiX[/eluser]
If you name the method the same name as the controller, that is the php4 style of creating a constructor (which gets executed no matter what the request is). CI uses the reserved 'index' method of a controller, which gets accessed if no method name is accessed in the request (http://yoursite.com/controller). So what's happening is first the constructor is called (index, because you named your class index), which outputs 'hi', then the actual index method is called by CI because there was no method specified, which also outputs 'hi'. The way to avoid that is to 1) use php5 constructors and 2) don't name your controller 'index' Code: class Test extends CI_Controller { going to http://yourhost.com/test triggers index() method and outputs "this is the index" going to http://yoursite.com/test/notindex triggers notindex() method and outputs "this is NOT the index" |
Welcome Guest, Not a member yet? Register Sign In |