Welcome Guest, Not a member yet? Register   Sign In
"super arrays" ? (Arrays available to every view)
#1

[eluser]Unknown[/eluser]
I've 2 tables in DB ('colors' and 'sizes'). They've their own controller/model/view to add/maintain records. Each one have ~50 records. Both are expected to grow occasionally.

Almost in every page of my application, I'll require the content of both tables (for filling select boxes). I'd like to have the selects filled accordingly *without* having to acces the DB (loading model, running query, load select boxes from query array), at every page (view) load.

I'd like to load both tables content (automatically ?) loaded to an array (SESSION ? ) (or CI's 'this' super object) using a class (library ? /helper ? ).

Resuming: Needing an auto-loadable script that access both tables, get contents, store them on arrays (or SESSION or '$this'), and holds them available, mostly in any view.

Can someone help me or point me to the right direction on this?

Thanks, best regards



#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You can either use hooks, or create a MY_Controller class that pulls the relevant data and extracts it for insertion into your views with $this->load->vars(). If you need them available to the app itself, you can store them as a property of your controller too.

You could also cache the results as a serialized array and throw it into a text file, so you pull your data from there rather than having to load your database. However, I don't see why it would be a problem to load the database, since the performance hit is pretty minimal. This is what the database cache library was made for.




Theme © iAndrew 2016 - Forum software by © MyBB