![]() |
Undefined index: except in_array() expects parameter 2 to be array, null given - 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: Undefined index: except in_array() expects parameter 2 to be array, null given (/showthread.php?tid=40406) |
Undefined index: except in_array() expects parameter 2 to be array, null given - El Forum - 04-07-2011 [eluser]johnmerlino[/eluser] Hey all, I'm trying to use the before_filter code posted here: http://ellislab.com/forums/viewthread/76228/ When I put this in one of my controllers: var $before_filter = array('name' => 'vanity_activated', 'only' => array('get_blogger')); And I have this in my routes: $route['blogs/([a-z_-]+)'] = "blogs/get_blogger"; I expect the vanity_activated method to execute only when people use urls like this: mysite/blogs/johnmerlino mysite/blogs/sallyann etc But two problems happen: 1) I get an exception: Severity: Notice Message: Undefined index: except Filename: hooks/Filter.php Line Number: 41 Severity: Warning Message: in_array() expects parameter 2 to be array, null given Filename: hooks/Filter.php Line Number: 41 2) It doesn't work as demonstrated. The method vanity_activated gets called before every method in the controller, not just the get_blogger one, which is what I want to happen. For the first problem I see what happens: if(in_array($called_function, $CI->before_filter["except"])){ call_user_func(array($CI,$CI->before_filter["name"])); } Because there is no 'except' in the array, since I am using 'only' instead, except is null here and rather than converting the statement to true or false for that if, it throws an exception saying in_array requires two arguments. Any way to address these problems? thanks for response Undefined index: except in_array() expects parameter 2 to be array, null given - El Forum - 04-07-2011 [eluser]johnmerlino[/eluser] I changed this: $CI->before_filter["except"] to this: $CI->before_filter["only"]. This make sense because only is in array as well as the callback, not except. You think mistake of original author? |