And to make it complete, my last update.. :).

You would want to put LoadModel inside the if that checks if the cache is 
still existing.
Otherwise it just adds overhead, and their is no point in using the cache.

This is the code:

<?php
class AppController extends Controller {
    function beforeFilter() {        
        $this->pfSettings = $this->getSettings();
        $this->fillLayout();    
    }
    
    function fillLayout()
    {
        $this->set('site_name', $this->pfSettings['name']);
        $this->set('site_title', $this->pfSettings['name']);
        $this->set('site_description', $this->pfSettings['description']);    
     
    }
    
    function getSettings()
    {        
        //check to see if they are in the cache.
        if (!$cachedSettings = Cache::read('settings')) {
            //load settings model
            $this->loadModel('Setting');
            //find all in the settings database
            if($settings = $this->Setting->find('all')) {
                $configurations = array();
                foreach ($settings as $setting):
                    $configurations[$setting['Setting']['key']] = 
$setting['Setting']['value'];
                endforeach;
                Cache::write('settings', $configurations);
                return $configurations;
            }
            else
            {
                //TODO: set error that settings failed
                exit();
            }
        } else {
            //return the cached settings.
            return $cachedSettings;
        }
    }
}

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to