Reverse wildcard search in codeigniter
Posted
by
Andy Platt
on Stack Overflow
See other posts from Stack Overflow
or by Andy Platt
Published on 2012-11-07T10:58:14Z
Indexed on
2012/11/07
10:59 UTC
Read the original article
Hit count: 146
I am implementing a snippet-based content management system into my current project. Snippets can be associated with a page either by exact match of the full url falling back to a wildcard match on a partial url or finally a default snippet.
To implement this I have a created table of page associations with a wildcard flag, the system first checks the current url against the non-wildcard associations and if it doesn't find a match it checks against the partial url's where the wildcard flag is set.
In order to achieve this I am getting all the partial url's from the database and putting them into an array then walking the array to check for a match against the current url:
protected function _check_wildcard($url = NULL)
{
if($url)
{
$q = $this->db->where('wildcard' ,'Y')
->from('content')
->get();
$wildcards = $q->result_array();
foreach($wildcards AS $wildcard)
{
if(strpos($url,$wildcard['url']) > 0)
{
return $wildcard['snipppet_id'];
}
}
}
else
{
return NULL;
}
}
Can anyone suggest a better way to do this - preferably one that doesn't involve having to constantly download the full list of all the wildcards each time I load a page as I am afraid that this will have a negative effect on the scalability of the system down the line?
© Stack Overflow or respective owner