Good CMS design, templates and other issues + performance

Good CMS design, templates and other issues + performance

am 22.01.2008 11:59:30 von webcm123

I hope you can spend some time and help me to select proper
application design and programming issues. :) I'm making new version
of CMS. I've been mostly theorizing about it for a recent months.


** Main Goals **
The main goal of this CMS is **speed and performance**. It should work
fast on slower or overloaded servers. Other goals are: easy appearance
editing, low size, care about input data (e.g. if error occurs, form
is sent to client with his input)... This CMS uses PDO for
communication with database.


** Let's start. Front Controller? **
There are some front controllers and other files in the main
directory:
* index.php - handles most requests
* login.php - login and logout
* adm.php - administration panel
* request.php - handling AJAX
* kernel.php - the most important file - connecting to database,
setting user, lang, style... general functions.
* other - e.g. go.php (downloading files, redirecting to links)

Are front controllers better solutions than separate module files
(which handle requests), e.g. art.php, image.php...?


** Details of index.php **
There are several versions of index.php depending on application
design.
http://pastebin.com/m7795f4c0 - index.php
http://pastebin.com/m41367c82 - content.php


** Problem 1. Access to tag. **<br /> In previous versions, all modules were included in <body> tag by the<br /> main template. Document Title was always constant (set in<br /> configuration). However, it's better to display currently displayed<br /> subpage's title in <title> - for users and for Google. :) So I was<br /> forced to change something. The first action was **setting it only for<br /> content modules** (see it in posted URL above).<br /> <br /> <br /> ** How to allow all modules to change <title> and <head>? **<br /> It's more difficult. I will explain you, why. However, let's begin<br /> from some methods of byways:<br /> <br /> * Output Buffering - everything what modules and their templates<br /> (included by modules) display, is buffered and assigned into $content<br /> variable. No problem with setting <title> and <head>. However, output<br /> buffering and assigning data into variable uses more RAM and may be<br /> little slower.<br /> <br /> * Template abstraction - all modules are included before <html>.<br /> They tell CONTENT object or class, what should be displayed. CONTENT<br /> class would offer some functions like: add(), info()... The main<br /> template displays content: <?= $content ?> (if we use __toString) or:<br /> Content::display(). Examples:<br /> <br /> > Content::add('filename', $data);<br /> > Content::info('information', $links);<br /> <br /> * Modules abstraction - modules are covered into classes. Before<br /> <html> index.php gets <title>'s text from them. In <body> the main<br /> template calls Module::display() or prints: <?= $module ?> (if we use<br /> __toString). Unfortunately, we **must use or define some global<br /> variables**, e.g. $cfg, $lang, $db, maybe too: $user... Example:<br /> <br /> > class News<br /> > {<br /> > /* some variables? */<br /> > /* __construct(), __toString() */<br /> }<br /> <br /> * FILE constant or $template variable - without abstraction. If<br /> FILE not defined, use $_GET['mod'] as FILE. Example:<br /> <br /> > define('FILE', 'template_file.php');<br /> <br /> * Another way?<br /> <br /> Remember that $lang and $db are used in all modules, $cfg in most,<br /> $user in some of them. They are global. What do you think about above<br /> methods and why?<br /> <br /> <br /> ** What do we need to display? **<br /> In some modules we have to display only one template. However, most of<br /> them may:<br /> <br /> * use more templates - I think I can use include() in one of these<br /> templates<br /> <br /> * display only information - examples: "user doesn't exist", "No<br /> votes in this poll", "No results". In the first case we can display<br /> 404 page instead. Sometimes we would like to put some links under the<br /> information.<br /> <br /> * comments - this submodule makes everything in global scope. In<br /> case of abstraction, I must cover it into class or function.<br /> <br /> <br /> ** Code repetitions **<br /> There are 5 content modules - articles, files, images, links and news.<br /> 4 of them have "details" page. In every of these 4 modules we must:<br /> <br /> * download data about item from database<br /> * IF item exists: download data of item's category (common)<br /> * display hierarchy of categories (common - function in kernel.php,<br /> but not good solution)<br /> <br /> Is it a problem to repeat some fragments of code? In the beginning of<br /> creating new version (you can see it in posted fragment of index.php)<br /> index.php included common content.php file. However, adding new type<br /> of content requires more modifications or we must create something<br /> like "content" plugins.<br /> <br /> Okay, I'm finishing this contemplation for now. I hope you will give<br /> me some advices. How would you solve my problems? Let's talk about it.<br /> If you want more examples or code of above methods, tell me. Remember<br /> that speed, performance and low RAM usage is important. :)</p> </article> <article> <h2>Re: Good CMS design, templates and other issues + performance</h2><span>am 22.01.2008 20:15:45 von webcm123</span> <p>Update:<br /> <br /> Maybe it won't be difficult to change <title> if I include all modules<br /> before <html>. However, there will be some consequences because of<br /> current CMS design.<br /> <br /> Which consequences? Read "what do we need to display?" section. :) How<br /> about displaying informations? Is it needed to make any abstractions<br /> (classes) or use output buffering? How about need of repeating some<br /> code in similar modules?<br /> <br /> PS. I don't want to use Smarty, etc.</p> </article> <footer> <a href="/">Index</a> | <a href="/impressum.php">Impressum</a> | <a href="/datenschutz.php">Datenschutz</a> | <a href="https://www.xodox.de/">XODOX</a> </footer> </main> </body> </html>