Re: Storing (html and php) Content in MySQL - help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allen McCabe wrote:
I have been trying to wrap my mind around how to accomplish this for a few
days, and done estensive searching on Google.

I know there are free CMS systems available for download, but I want to
write my own code so I can maintain it and extend it, I need it to be
customizable.

So far what I have worked up is this:

The mysql row contains a page_id field, title field, content field, and
sidebar content field.

in index.php:
include("module.php")
$username = findLoggedinUsername()

eval ($content)


in module.php:
$result = mysqlquery("select * from content where page_id = get['id']")
$row = fetcharray9$result)
$content = $row['content']
$title = $row['title']

etc.

The content mysql field contains:

$ct = <<<END
<p>Welcome $username, to the interweb</p>
END;

echo $ct


In the heredoc, I can use variables like $username, but not like
$row['username'].

So far this method works just fine, however I want to be able to edit the
content through the website itself. Am I on the right track or is this
awkward? I am implementing a new, login system (mine isn't secure enough)
and I want to implement it correctly.

How should I go about storing content (which may or may not include php)
into a page content field?

You are definitely trying to reinvent the wheel.

But, having done that myself, I can tell you very generally how I did it.

My content table allowed for multiple rows for each page. Each row had a label and value (e.g. body:Hello World, sidebar:Goodbye World). To allow for php code, I added a "type" to each row. (e.g. body:text:Hello World, sidebar:eval:echo 'Goodbye World';). A template then would have a function call at the appropriate places to parse the expected content elements.

As things go, it got a little more complex than that, and then a little more complex than that, etc.

It's been working fine for me for five or six years and is still reasonably elegant. I've thought of open sourcing it, but I have a hunch there are several hundred systems like that already.

Good luck and have fun.

John



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux