Welcome Guest, Not a member yet? Register   Sign In
How To Get Global Data From DB?
#1

[eluser]Unknown[/eluser]
Hello,

I'm very new to CodeIgniter and I'm learning as I'm developing a web service for a project I'm working on. I've got a simple question. Maybe it's been because I've been working as a WordPress dev for a while, but how do you save and pull global data from a DB?

For Example.

I'm developing a set of templates and I have my sites admin email, website name, etc stored in a Database table. I'd like to be able to build a series of templates where I can pull those fields from the database table I have them in. In the template, I just need to do a call using a tag similar to Wordpress like "<?php echo bloginfo('blogname'); ?> and have it echo that fields content.

I don't want to have to set these settings every time for every page I have to create a controller for. I would have figured there is a way to create a single global controller and model or even a Helper that would allow me to create the function to call to the model where the search is done and publish it to the view's tag.

Now I've been messing around with this for the past few hours and it's really bothering me. I get how codeIgniter is fine for creating per page, but there is some data I need to be able to grab globally for any page. Can someone explain this to me? And please be remember I'm new at this, so please be kind and think of me as a monkey holding a mouse trying to figure this out when you explain.

Thanks
#2

[eluser]Otemu[/eluser]
Hi,

Quite a common question that has been answered a few times, I provide you some links to some resources that give good explanation how to achieve this:

Extending Class
http://ellislab.com/forums/viewthread/212750/#985956
http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY

Creating libraries
http://ellislab.com/codeigniter /user-guide/general/creating_libraries.html
http://blog.zeratool.net/2008/02/03/crea...deigniter/




Theme © iAndrew 2016 - Forum software by © MyBB