PHP Classes
elePHPant
Icontem

File: Example1.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ivan Priorov  >  keeper  >  Example1.php  >  Download  
File: Example1.php
Role: Example script
Content type: text/plain
Description: Example file
Class: keeper
Store and retrieve keys in array static object
Author: By
Last change:
Date: 4 years ago
Size: 1,333 bytes
 

Contents

Class file image Download
<?php
require_once 'Keeper.php';
/*
 * For example:
 * You have created the site menu in the header and footer.
 * These menus are created in different files (modules), using the same array,
 * which returns a function mysql_fetch_assoc();
 */

# file (module) generation head menu
$query = "SELECT * FROM `menu` ORDER BY `sort` ASC";
$result = mysql_query($query);
$menu = mysql_fetch_assoc($result);

# and file (module) generation footer menu
$query = "SELECT * FROM `menu` ORDER BY `sort` ASC";
$result = mysql_query($query);
$menu = mysql_fetch_assoc($result);

# Well... I propose to change the approach.
# file (module) generation head menu
$key_by_keeper_registry = 'Menu array assoc';
if (
Keeper::exists($key_by_keeper_registry)) {
   
$menu = Keeper::get($key_by_keeper_registry);
} else {
   
$query = "SELECT * FROM `menu` ORDER BY `sort` ASC";
   
$result = mysql_query($query);
   
$menu = mysql_fetch_assoc($result);
   
Keeper::set($key_by_keeper_registry, $menu);
}
# and file (module) generation footer menu
$key_by_keeper_registry = 'Menu array assoc';
if (
Keeper::exists($key_by_keeper_registry)) {
   
$menu = Keeper::get($key_by_keeper_registry);
} else {
   
$query = "SELECT * FROM `menu` ORDER BY `sort` ASC";
   
$result = mysql_query($query);
   
$menu = mysql_fetch_assoc($result);
   
Keeper::set($key_by_keeper_registry, $menu);
}
?>