retrieving id value in controller

I have problem about retrieving id value in controller,

for example

i have controller productList, this is a piece of written code


public function actionView($routeUrl,$id=null)

        {

            echo 'routeUrl = '.$routeUrl .', id = '. $id;   

        }

so i wanna take a test to view value of described parameter

  1. http://www.example.com/productList/view/routeUrl/product/id/9 => displays: routeUrl = product, id = 9

  2. http://www.example.com/productList/view/routeUrl/product => displays: routeUrl = product, id =

  3. http://www.example.com/productList/view/routeUrl/product/sugar/id/9 => displays: routeUrl = product, id = (incorect value)

  4. http://www.example.com/productList/view/routeUrl/product/sugar => displays: routeUrl = product, id = (incorect value)

I wanna ask for incorect value of test above

for point 3, how to get routeUrl value become "product/sugar" and id value = "9" so when display to browser return "displays: routeUrl = product/sugar, id = 9"

can anyone want to help?

i think you need to encode your product, that you need to prepare it for passing through get