Search code examples
codeignitercodeigniter-routing

Empty parameters in codeigniter url


I have a controller which takes 4 parameters. Sometimes parameters can be empty. Standard url is like review/fetch_reviews/10/uk/topcomments/1234 where 10 represents count for paging.If that parameter is blank then url becomes review/fetch_reviews//uk// and my sql query becomes select * from table limit uk,10. I even set default value for parameters as bellow

function fetch_reviews($page="10",$banktype="",$country="",$filter=""){

how to handle this? Itried URI routing but t doesnt work.


Solution

  • You can set your functional parameter as optional and pass this optional value like

    Url:

    site.com/class/myfunction/para1/null/para3

    and function

    public function myfunction($para1,$para2="null",para3) { //function body }