0

I have a database table with some information about the website such as the site title, phone numbers etc... This information is needed on every page. Is there a way i could get those database values into variables on every page without having to write the same code in every page controllers?

Thanks, Marais

6
  • 1
    put the logic getData() into the model that handles the database table; then call the method from any controller you need; If you're making the same call from different controllers during a single request just use caching to avoid querying the database again for the same data Commented Feb 26, 2012 at 23:44
  • But this will still require me to have repeated code in each controller... Commented Feb 27, 2012 at 0:20
  • 1
    yes but that will be just two lines such as $data = $this->some_model->get_data(); $view['data'] = $data; Commented Feb 27, 2012 at 8:23
  • true, i guess that is smaller. Thanks that works!! :D Commented Feb 27, 2012 at 10:17
  • well you can't not repeat some code if you want the same data/functionality in different places; the point is to keep the duplication to minimum; there is definitely nothing wrong with calling the same function from different places Commented Feb 27, 2012 at 10:19

1 Answer 1

1

How about using autoloading of codeigniter AutoLoader

Create your custom helper and the method to get the data you needed from your database, then just call the method on every view file that you need it to be shown.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.