Reputation: 33
I just wanted to get your opinions on how I plan to handle a situation.
Situation: I am developing a school's website where strict Board of Education policies will not allow anyone BUT me FTP access to the site. However, the school will have a group of six students in a "webpage" class to manage 10-12 pages that need frequent updating.
The pages all look pretty identical: header, navigation, side navigation (for that specific section (sports, academics, etc)), and the main content.
The main content is served by the div "content", so what I'm thinking to do is just to load all of #content's content from a Mysql db that is edited with another file (I pretty promise to use prepared statements).
Do you have any opinions on this, or maybe a better method? Thank you!
Upvotes: 3
Views: 190
Reputation: 8701
When you kepp your markup in a database, in order to get that one you need:
When you keep your markup in a file, all you need to do is include that markup via require()
language construct
EDIT
To be very specific - No. it's not a bad idea to store dynamic HTML content in a table. This is a common practise. But if you also store static content like header, navigation in a table for each page, it merely leads to data duplication.
I personaly would store the parts I never change in a file. The parts that tend to be "dynamic" I'd store in a table. I would add/edit them via TinyMCE using jquery-ajax.
An example of how I do that:
File: page_view.php
<?php
class Page_View // <- This isn't MVC
{
private $data = array();
public function render()
{
include('page_template.phtml');
exit();
}
private function getTitle()
{
return $this->data['title'];
}
private function getBody()
{
return $this->data['body'];
}
private function getStaticBlock($file)
{
include($file);
}
public function setBody($body)
{
$this->data['body'] = $body;
}
public function setTitle($title)
{
$this->data['title'] = $title;
}
}
File: page_template.phtml ?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $this->getTitle(); ?></title>
<?php $this->getStaticBlock('/templates/blocks/header.phtml'); ?>
<body>
<div id="navigation">
<?php $this->getStaticBlock('/templates/blocks/navigation.phtml'); ?>
</div>
<div id="content"><?php echo $this->getBody(); ?></div>
</body>
</head>
</html>
Example of usage:
<?php
// $data is what you got from a table
$page = new Page_View();
$page->setTitle($data['title']);
$page->setBody($data['body']);
$page->render();
Upvotes: 2
Reputation: 3771
Yes, storing arbitrary HTML in a database is a nightmare to maintain and secure. I'd look more closely at what you are trying to accomplish before engineering a new solution.
I'd strongly recommend a content management system. They're equipped to deal with this sort of work and there's no sense in rebuilding one from scratch.
If the selected students are going to be frequently updating the website, consider separating out that part of the site.
For example, if the main website is static but the frequently updated parts are a blog, set up a static site and either a subdomain or a sub-directory with a wordpress blog in it.
If the students are going to be editing the actual content of the page, a CMS like Drupal is far more effective for the task.
Upvotes: 1