![]() |
array_walk inside controller class - 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: array_walk inside controller class (/showthread.php?tid=7679) |
array_walk inside controller class - El Forum - 04-18-2008 [eluser]somewhatjaded[/eluser] In the process of reading in a csv (created w/ CI dbutil), and mapping out values to a database for import, I found the following solution for escaping any data (as it changed slightly when coming back from an excel save). I wasn't able to use mysql_real_escape_string with an array_walk, due to the scoping. Using Code: array_walk($fdata,'mysql_real_escape_string'); Quote:A PHP Error was encountered I'm sure there's another way to pass in the correct namespace. 2nd param of array_walk is: Code: array("DON'T KNOW", 'mysql_real_escape_string) Here's my solution, using a virtual function: Code: $handle = fopen($udata['full_path'], "r"); //from the upload library I realize you could just sanitize within the model, but it seemed to make more sense to pass in clean data, to make the model function more reusable. Hope that saves someone else the struggle! *EDIT I was also able to use the following with success: Code: $handle = fopen($udata['full_path'], "r"); //from the upload library Using the profiler, they both seem to use approx. the same memory/execution time for a small file, with the array_map possible having a slight edge in performance, and array_walk the edge in job security :coolsmirk: array_walk inside controller class - El Forum - 04-19-2008 [eluser]Seppo[/eluser] The problem with array walk is not a CI issue... Array walk passes, at least, two parameters, which are the value and the key. mysql_real_escape_string accepts two parameters: the value and the connection ID... So if you want to use array_walk instead you can create your own callback that receives the value, and may be the key and the connection id. |