OK, what I need may sound fairly easy (or complicated? - I don't know), but here it is :
In CodeIgniter, given a controller e.g. test you can do :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class test extends CI_Controller {
public function sub($param1="", $param2="")
{
}
}
?>
Which means that you can access either :
- mysite.com/test/sub
- mysite.com/test/sub/someparam1
- mysite.com/test/sub/someparam1/someparam2
However, what happens if I want to "omit" the sub part?
Ok, so I thought about doing the very same thing in the index function of the controller. Like :
public function index($param1="", $param2="")
{
}
So that I could directly access either :
- mysite.com/test
- mysite.com/test/someparam1
- mysite.com/test/someparam1/someparam2
However, given CI's inner design, when I try this, it keeps looking for a someparam1' method in thetest` controller which obviously does not exist.
So, what how would you go about that?
P.S.
1. Please, let's avoid solutions having to do with .htaccess and obscure redirections and let's stick to the most CI-friendly approach available (if there is one).
2. Don't suggest my creating the appropriate functions (instead of using some variable accessor) - if I wanted to do it this way, I would already have done it
3. The parameters should preferably be part of a SEO-friendly URL, and not take them with $_GET, etc. (e.g. mysite.com/test/?param1=someparam1¶m2=someparam2)