Codeigniter. How to pass parameters $ _GET in the route.php?

懵懂的女人 提交于 2019-12-12 07:00:31

问题


This code $route['basketball'] = "controller/product/?id=7" does not work.

function product()
{
    echo $_GET['id']  // no output
}

How to describe the rules in the route?


回答1:


If possible use CodeIgniter's standard URL routes. In your case:

$route['basketball'] = "controller/product/7";

function product()
{

}

OR if $_GET['id'] needs to be dynamic

$route['basketball/:num'] = "controller/product";

function product($id)
{

}

Hope that helps.




回答2:


Because you are in PHP , you can basically set $_GET and $_REQUEST parameters which are super global variables that can be accessed anywhere in the code. So you can do a callback and set them there.

For example:

$route['basketball'] = function(){
  $_GET['id']=$_REQUEST['id'] = 7;
  return "controller/product/";

};

Then in your code you can access $_GET['id'] or whatever.



来源:https://stackoverflow.com/questions/24749616/codeigniter-how-to-pass-parameters-get-in-the-route-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!