开发者

Codeigniter URI Routing not working till parameter

In my router.php file I added this code.

$route['mission'] = "content/index/mission";

Here as you know content is controller, index is function and mission is parameter to that function.

But when i check it in my browser, it takes me to开发者_如何学Go content/index . In other words, it is not passing required parameter to index function.


Make sure your recieving the parameters through the function parameters and not using uri segments.
Controller:

// This is incorrect, and will not work
public function index()
{
    $param = $this->uri->segment(3); // This wont work
}

// This is correct and will work.
public function index($param = null) // use null to prevent "undefined var error"
{
      if($param != null)
      {
          // The param was passed and do your stuff here
      }
}    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜