![]() |
What's the best way to handle a function with multiple parameters... - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: What's the best way to handle a function with multiple parameters... (/showthread.php?tid=31729) |
What's the best way to handle a function with multiple parameters... - El Forum - 06-29-2010 [eluser]dallen33[/eluser] I have a model with a function called get_user. It looks like this: Code: function get_user($create_dropdown = FALSE, $form_name = FALSE, $order_field = FALSE, $order_by = FALSE, $role_id) Code: echo $this->database->get_user($create_dropdown = TRUE, $form_name = $name, 'first_name', 'asc', $role_id = '4'); I feel like I'm going about this all wrong. What's the best way to handle a function with multiple parameters... - El Forum - 06-29-2010 [eluser]Buso[/eluser] what I usually do is to send an array instead. Then check if isset() for each key, OR set a default value for it. eg: Code: isset($options['create_dropdown']) OR $options['create_dropwdown'] = FALSE; What's the best way to handle a function with multiple parameters... - El Forum - 06-29-2010 [eluser]dallen33[/eluser] Great idea! That's exactly what I needed. Thanks! |