Welcome Guest, Not a member yet? Register   Sign In
Active Record ->like doesn't take the 3rd option
#1

[eluser]Unknown[/eluser]
Per the CI doc (http://ellislab.com/codeigniter/user-gui...ecord.html), I was trying to generate something like:

$this->db->like('name', $name, 'after');

it seems to ignores the 'after' (or 'before' for that matter) altogether. Upon examination of the code (db_active_record.php under the drivers folder), it seems that the AR 'like' isn't looking at the 3rd optional parameter at all.

Is this a real bug or am I just seeing things? Thanks.
#2

[eluser]Michael Wales[/eluser]
What version are you using? I am looking at 1.7.0 right now, the like() method calls _like(), which I have pasted below. It definitely takes the third parameter into account:

Code:
function like($field, $match = '', $side = 'both')
{
    return $this->_like($field, $match, 'AND ', $side);
}

function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '')
{
    if ( ! is_array($field))
    {
        $field = array($field => $match);
    }
    
    foreach ($field as $k => $v)
    {
        $k = $this->_protect_identifiers($k);
            $prefix = (count($this->ar_like) == 0) ? '' : $type;
            $v = $this->escape_str($v);
            if ($side == 'before')
        {
            $like_statement = $prefix." $k $not LIKE '%{$v}'";
        }
        elseif ($side == 'after')
        {
            $like_statement = $prefix." $k $not LIKE '{$v}%'";
        }
        else
        {
            $like_statement = $prefix." $k $not LIKE '%{$v}%'";
        }
        
        $this->ar_like[] = $like_statement;
        if ($this->ar_caching === TRUE)
        {
            $this->ar_cache_like[] = $like_statement;
            $this->ar_cache_exists[] = 'like';
        }
        
    }
    return $this;
}


If you are on 1.7.0, try using an array for your parameters as opposed to the strings.
#3

[eluser]Unknown[/eluser]
ahhh. I was looking at someone else's code and it seem they're on 1.4.x. Sorry about this confusion. I'll update their version and then we should be good once again.
#4

[eluser]Michael Wales[/eluser]
Yeah, this was added at 1.6.0 or 1.6.1 - changelog has the info.




Theme © iAndrew 2016 - Forum software by © MyBB