optional parameters in CodeIgniter optional parameters in CodeIgniter codeigniter codeigniter

optional parameters in CodeIgniter


  public function my_optional_test($not_optional_param, $optional_param = NULL)  { $this->stuff(); }

have you tried this?


For example, let’s say you have a URI like this:

  1. example.com/index.php/mycontroller/myfunction/hello/world
  2. example.com/index.php/mycontroller/myfunction/hello

Your method will be passed URI segments 3 and 4 (“hello” and “world”):

class MyController extends CI_Controller {

public function myFunction($notOptional, $optional = NULL){    echo $notOptional; // will return 'hello'.    echo $optional; // will return 'world' using the 1st URI and 'NULL' using the 2nd.}

}

Reference: https://codeigniter.com/user_guide/general/controllers.html