Welcome Guest, Not a member yet? Register   Sign In
Clarification on database access in helpers, models and plugins
#1

[eluser]Ki[/eluser]
I wanted to ask for a clarification. I am not sure if I need to use model or plugin or helper for this. I am leaning towards a helper.
When users search for something on my website, they have many parameters to set for their search, such as price, category etc. I want to display the filters on the search page that are applied to current search. So I would create a function, that would read the URL as array in my controller, then it will load helper/model/plugin, which will help in filtering only search filters. For example, it will look for category_id/26 or price/150 in my url array. This helper/model/plugin will only take the url values I define as filters and strip away everything else.
The problem is that if url contains category/26, I dont want to display
Filters
category: 26
I want to display
category: parts

In doing so, whenever my my helper/model/plugin comes across category > 0 in url array, it will pull up the description from the database. Now, I could pass the category array to the helper, but since I have about 5-6 search filter that need description from db I dont want to pass 5-6 array every time.
As far as I know, helpers and plugins do not actyaly allow db acces, even if you extend Controller.
So should I put this into a model? or helper and set instance of CI?
Maybe I am way off and there is an easier way to do this?

I am trying to keep this db querying out of controller, so I dont have to pass unnecessary variables and have helper/model/plugin access db only when it detect url parameter that requires db access. I pre-define these parameters in array inside the helper/model/plugin as such:
$filters=array('category_id'=>array('function'=>'get_category_name','display_name'=>'category'));
Then I do array_intersect_key with url array and when it detects 'category' and sees that $filters=array['category_id'][function] != '' it calls the function defined in $filters=array['category_id'][function], which goes to db and gets the 'human' category name

Thank you in advance


Messages In This Thread
Clarification on database access in helpers, models and plugins - by El Forum - 09-28-2009, 03:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB