one controller method with multiple input params |
[eluser]ronnixw[/eluser]
example from user guide: class Products extends Controller { function shoes($sandals, $id) { echo $sandals; echo $id; } } my problem: I want to call method shoes with dynamic param count ( 2 , 3 or more ) not only with stacic defined. is it possible? best regards, ronnixw
[eluser]ronnixw[/eluser]
but if I call function with non maching param count - there is an error?!
[eluser]Clifford James[/eluser]
Code: class Products extends Controller {
[eluser]Unknown[/eluser]
[quote author="Clifford James" date="1292359229"] Code: class Products extends Controller { is this considered good practice to use on a regular basis, or should it only be used in special/specific situations? I usually just define the $params with a default value which controls the behavior if there is no input. Code: function shoes($param1 = 'default-1', $param2 = 'default-2') I use this a lot for things such as table of contents so you don't have to define an exception for 'toc' (its the default behavior) e.g., controller/method/ displays the same as controller/method/toc. would I be better off redesigning it to around func_get_args(); ?
[eluser]Unknown[/eluser]
[quote author="ronnixw" date="1292358755"]but if I call function with non maching param count - there is an error?![/quote] Not necessarily. You can handle the exception using a default procedure. Code: function shoes()
[eluser]Atharva[/eluser]
Another simple way is to use array as parameters so that you can pass as many parameters as you like. So there is no need to give default/static values. For sending emails, I use this method Code: $param['from'] = '[email protected]'; You can utilize this technique according to your needs.
|
Welcome Guest, Not a member yet? Register Sign In |