passing variable into anonymous function - form validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: passing variable into anonymous function - form validation (/showthread.php?tid=64038) |
passing variable into anonymous function - form validation - webdeveloper - 01-06-2016 Hello, i would ask simple question. is there any possibility to pass own parameter into anonymous function in set_rules for form_validation like its shown in first example below or its just possible to pass it trought callback function ? Thank you Code: $this->load->model('admin/currency_symbols_model', 'currency_symbols'); RE: passing variable into anonymous function - form validation - Narf - 01-06-2016 Not possible in the way you want it to, but not necessary either: Code: $currency_id = 1; // your custom parameter EDIT: But actually, your code wouldn't work anyway as $this inside the anonymous function refers to the function itself, not to your controller, so you actually MUST use the use keyword to pass your currency_symbols object ... updated the code above. RE: passing variable into anonymous function - form validation - webdeveloper - 01-06-2016 ok in that case it isnt readable very well and not usefull so much (strange way to do that) .. i will use rather callback function .. there i can pass any variable and inside callback function $this refers to controllers class ... thanks for answer |