Welcome Guest, Not a member yet? Register   Sign In
Undefined index: except in_array() expects parameter 2 to be array, null given
#1

[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
#2

[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?




Theme © iAndrew 2016 - Forum software by © MyBB