1

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.

www.amitpatil.me
  • 3,001
  • 5
  • 43
  • 61
  • You can pass // it self to pass empty parameted e.g. site.com/class/function/papra1/para2//para4, Here para 3 is missing; however you have to set para3 as optional parameter in function like para3='' – Chintan7027 Sep 04 '15 at 10:37

1 Answers1

0

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 }

Chintan7027
  • 7,115
  • 8
  • 36
  • 50
  • Thannks for the reply. I did that but the whats's happening is, insted of considering it as a null its assumes that para2 is passed at place of para1, So my query "limit 10,10" becomes "limit uk,10" – www.amitpatil.me Sep 04 '15 at 11:08
  • Uhh quite strange issue class/myfunction//undefined// this works fine, but class/myfunction//retail// throws error :D :D So i added condition if($currpage == "undefined" || !is_numeric($currpage)) $currpage = 0; Now it worked. Thanks chintan for clue. – www.amitpatil.me Sep 04 '15 at 11:20