Salman Aslam
Salman Aslam

Reputation: 781

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 content/index . In other words, it is not passing required parameter to index function.

Upvotes: 0

Views: 629

Answers (1)

Anil
Anil

Reputation: 21910

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
      }
}    

Upvotes: 2

Related Questions