ok, need may sound easy (or complicated? - don't know), here :
in codeigniter, given controller e.g. test can :
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class test extends ci_controller { public function sub($param1="", $param2="") { } } ?> which means can access either :
- mysite.com/test/sub
- mysite.com/test/sub/someparam1
- mysite.com/test/sub/someparam1/someparam2
however, happens if want "omit" sub part?
ok, thought doing same thing in index function of controller. :
public function index($param1="", $param2="") { } so directly access either :
- mysite.com/test
- mysite.com/test/someparam1
- mysite.com/test/someparam1/someparam2
however, given ci's inner design, when try this, keeps looking someparam1' method in thetest` controller not exist.
so, how go that?
p.s.
1. please, let's avoid solutions having .htaccess , obscure redirections , let's stick ci-friendly approach available (if there one).
2. don't suggest creating appropriate functions (instead of using variable accessor) - if wanted way, have done it
3. parameters should preferably part of seo-friendly url, , not take them $_get, etc. (e.g. mysite.com/test/?param1=someparam1¶m2=someparam2)
try in config/routes.php
$route['test/(:any)'] = 'test/index/$1';
Comments
Post a Comment