如何在codeigniter中指定给定参数

时间:2013-12-18 09:28:13

标签: php codeigniter

我有一个带3参数的控制器函数。为所有这些参数设置了默认参数 当调用此函数时,如果我必须仅给出第3个参数,我该如何指定我传递第3个参数

public function manage_class($msg="",$id=0,$class_type="all") 

i want to call this function only by the 3rd parameter 

3 个答案:

答案 0 :(得分:0)

我认为如果将null传递给第1个和第2个参数,它将获取默认值

像:

manage_class(null,null,3rd_value)

答案 1 :(得分:0)

方法是首先设置参数,可能更改默认值,然后严格默认值: public function manage_class($class_type="all", $msg="", $id=0)。也许我错了,或者其他什么。

顺便说一句,如果你只需要传递一个参数,为什么要将另外两个作为参数传递?

答案 2 :(得分:0)

那么在这种情况下你可以像我上面说的那样定义函数manage_class,然后使用数组:

manage_class($args = array())
{
//do something with this
echo $args['third'];
}

然后你可以用这样的URL来管理manage_class(s​​itename / call_manage_class / null / null / foo

call_manage_class($first, $second, $third)
{
   if($first == null) {
   $first = "";
   }
   //etc
   manage_class(array('first'=>$third
                      'second'=>$second
                      'third'=>$third));
}