 |
Aug 16, 2007, 11:43 AM
|
#1
|
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086 Yapper(s): 1000547083912.40 ( Donate)
|
K, I'm developing a simple script that allows me to edit/store my xhtml code in a database and have php pages extract it. However when caching each of the templates in php variables it doesn't seem to want to print them out. Can anyone please help:
index.php:
PHP Code:
define('THIS_SCRIPT', 'index');
$templates = array(
'index'
);
require_once('include/global.php');
eval(print_template('header'));
eval(print_template(THIS_SCRIPT));
eval(print_template('footer'));
global.php:
PHP Code:
require_once('config.php');
require_once('classes.php');
require_once('functions.php');
db_connect();
if (!is_array($templates)) {
$templates = array();
}
$templates = array_merge($templates, array(
'header',
'footer'
));
cache_templates($templates);
unset($templates);
functions.php:
PHP Code:
function db_connect() {
global $config;
if (isset($config['Server']['usepconnect'])) {
$link = mysql_pconnect($config['Server']['host'], $config['Server']['username'], $config['Server']['password']);
} else {
$link = mysql_connect($config['Server']['host'], $config['Server']['username'], $config['Server']['password']);
}
if (!$link) die('Unable to connect to ' . $config['Server']['host'] . ': ' . mysql_error());
$db_select = mysql_select_db($config['Database']['name'], $link);
if (!$db_select) die ('Unable to connect to ' . $config['Database']['name'] . ': ' . mysql_error());
}
function cache_templates($templates) {
global $db, $config;
$templates = mysql_query("SELECT title, code FROM template");
while ($template = mysql_fetch_array($templates)) {
$templatecache["$template[title]"] = $template['code'];
}
@mysql_free_result($templates);
//at this line of code all $templatecache variables are correct.
//the function below is the next function called
}
function print_template($title, $escape = 0) {
global $db, $config, $templatecache;
//$templatecache globalized
//as of this line of code the $templatecache variable is empty.
if (!empty($templatecache["$title"])) {
$template['code'] = $templatecache["$title"];
} else {
$template['code'] = $db->query_fetch("SELECT code FROM template WHERE title = '$title'");
}
}
Why would the $templatecache variable be emptied/unset after that function ended?
Last edited by Nullified : Aug 16, 2007 at 11:48 AM.
|
|
|
Aug 16, 2007, 12:13 PM
|
#2
|
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086 Yapper(s): 1000547083912.40 ( Donate)
|
Disregard last, I just had to globalize the variable in the cache_template function.
I do have another question though. Being that the xhtml code is being grabbed from the db and stored in php, if I update the db code, when will the site visitor have the updated code pulled form the db? Will they have to leave the site and come back (not using sessions).
|
|
|
Aug 16, 2007, 1:03 PM
|
#3
|
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 4,068 Yapper(s): 1273300250.60 ( Donate)
|
From the way it looks coded, as long as the global variables are active, the templates will remain in cache. One way would be possiblt to check if an update has occured to the template? Possibly a global refresh time for your entire system, but considering most users remain on a website for few minutes, it would be kind of redundent...
__________________
»» eBypassnow Launched :: Bringing the e to free access
»» Click Here to Access! :: http://www.ebypassnow.com
»» Premium Access for eWeb Members!
|
|
|
Aug 16, 2007, 1:12 PM
|
#4
|
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086 Yapper(s): 1000547083912.40 ( Donate)
|
what are you thoughts as far as speed? is it worth it to store html in the db and retrieve it with php as I am doing? Will the speed make up for the complicated editing? in your opinion. I really don't know if it'll be that beneficial since I don't see myself putting that much php related material on the pages.
|
|
|
Aug 17, 2007, 12:17 PM
|
#5
|
Join Date: Aug 2004
Location: Ontario, Canada
Posts: 4,068 Yapper(s): 1273300250.60 ( Donate)
|
I have recently been working on IR system based entirely on searching for images, and outputting them dynamically to increase security. I had the same questions as you did, are 'flat-file' templates better than ones stored in a database. Throughout most of my search, and finally in an application driven site, I think it is better to store them within a database or something more than simply a flat-file, especially if you will be expanding on the system after deployment. In terms of search/editing complexity, I was thinking of allowing the users to edit these templates much like how vB does, and the best way to accomplish this would be the use of database for storage and retrieval. In speed sense, its a harder question, many say that files are accessed faster than lets a database query since they are on the local system, while database can have a overhead, while others say that today's DB systems make this argument irrelevant. I would tend to agree with the latter arguement. Speed really boils down to be insignificant I think, especially if your database structure is optimized and well thoughtout.
__________________
»» eBypassnow Launched :: Bringing the e to free access
»» Click Here to Access! :: http://www.ebypassnow.com
»» Premium Access for eWeb Members!
|
|
|
Aug 29, 2007, 3:47 PM
|
#6
|
Join Date: Dec 2004
Location: Outer Space
Posts: 2,086 Yapper(s): 1000547083912.40 ( Donate)
|
Not even sure if I'm going to go through with it. It's going to be such a pain to edit the pages, and using an editor such as dreamweaver will be pretty much pointless.
|
|
|
May 26, 2008, 7:50 AM
|
#7
|
|
Join Date: May 2008
Posts: 95
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 6:54 AM.
|
 |