• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
action with the same name as the controller

#1
[eluser]tomas[/eluser]
If I create a new controller, let's say Test and then add index and test actions,
going to index.php/test/test executes the index action instead of the test action

Code:
class Test extends CI_Controller {

    public function __construct(){
        parent::__construct();
    }
    public function index(){
        echo 'here';
    }
    
    public function test(){
        echo 'there';
    }
}

navigating to
Code:
index.php/test/test
outputs 'here' instead of 'there'

#2
[eluser]Unknown[/eluser]
I have no solution for you but I just want to warn you.

Depending on your php version, a method with the same name as the classname can become the constructor of this class.

There's few lines hidden in the middle of nowhere about that in the php manual.

So I think it can be a bit dangerous doing things like this.
It's just my opinion... Perhaps you really need to do that !

#3
[eluser]pornnarnold[/eluser]
[quote author="Pexirouque" date="1311088447"]I have no solution for you but I just want to warn you.

Depending on your php version, a method with the same name as the classname can become the constructor of this class.

There's few lines hidden in the middle of nowhere about that in the php manual.

So I think it can be a bit dangerous doing things like this.
It's just my opinion... Perhaps you really need to do that ![/quote]

Pretty much as above.
I would probably suggest renaming the method to something else and creating a route to access the method at that address. I would assume that is possible.

#4
[eluser]Aken[/eluser]
It's confusing to have redundant information in the URL structure, anyway. I would avoid it all together.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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