suggestions to develop my own (simple) CMS

Posted on 2006-05-18
Last Modified: 2012-05-05

I have a basic PHP4 and MySQL knowledge but low object programming knowledge. I developed some small PHP web applications, a wordpress plugin but I never did programming classes. Thus some of you may tell that my way would be "old school scripting".

I know that there are some coding standards like Pear, there are caching systems, or template engines like smarty, but I never went in depth into them (I've just tried smarty once but it didn't satisfy me a lot, maybe i should retry again, or d you know better template engines?)... would you recomment me to learn some particular coding standards, frameworks, particular applications (e.g. like Eclipse? or Zend Studio?), template engines, caching systems? If yes, which ones?

I would like to improve my PHP knowledge by developing a very simple CMS. I already created a simple PHP4 script powered by the ezsql class ( ). Actually I have a page to insert/edit content into the DB and I use a WYSIWYG editor: Tiny MCE. Then I have a PHP page to display the pages taking the contents from the database records.

Thus I have a very simple and working CMS, but I'd like to extend it by adding templates support (should I use something like smarty, that already has a templating system?), cache support and eventually an ability to create html pages all at once by taking all the pages from the DB like movable type does.

I'm expecting suggestions from expert PHP developers. If you are a PHP beginner like me, please don't answer. Thank you.
Question by:firepol
    LVL 5

    Assisted Solution

    > templates support (should I use something like smarty, that already has a templating system?)

    There's a pretty big debate over templating systems, with some arguing that PHP, at it's core, IS a templating system -- why write a templating system inside a templating system? (Besides the other question, why write an interpreted language in an interpreted language?) Others say that templating languages are easier for the graphics people to understand. If you're commited to having some sort of templating language, using a pre-existing one would probably cut down on the amount of code you have to write. Also, your user's might already be familiar with the templating language if you pick one that's popular (like Smarty), and they wouldn't have to learn anything new.

    > cache support

    This can range from very simple to pretty complex. Does your CMS accept query string arguments that will change the content of the page (other than the page name/id)? If it does, you'll have to take those values into account when determing the name for your cache. Other than that, it can be some simple file reading/writing code, and use the last update time on the file to expire the cached data after a given TTL (time to live). For instance, if you get a request to page.php?id=1, you first look for cache/1.html before hitting the database. If it exists, and it was created within the past X minutes, you simply return that page to the browser.

    >  an ability to create html pages all at once by taking all the pages from the DB

    This can get a little tricky, since the pages may contain links to the PHP version of the pages, which you'll need to convert to point to the static content. Not impossible, though. If you don't accept query string arguments, and your pages are all accessed by a name/ID, you can pretty much just transverse the page table, render each page, replace any links to (for example) page.php?id=1 to /pages/1.html then save it as, say, /pages/[id].html.
    LVL 5

    Accepted Solution

    >Template Engines.

    There are allot of template engines out there, and most of them quite simple to understand. If you are realy looking to learn the trade and pick something up on templating do look into the phpBB templating engine and its code. If uses allot of expressions to parse the code. also request some tuts here, he can teach you allot on object orientated programming (

    > Data Model

    Dive into Datamoddeling. Learn how to effectivly set up a database and how to design one. Also look into Normalisation Forms used in relative database designs. Usually a good datamoddel helps you write simpler code and shorter scripts.

    > Functional model

    Think out a functional model for you CMS, for instance how do we handle errors, or log sessions and track them etc. Use a modular look to this and it gets quite easy to define and afterward write.

    >Recycling code.

    Sure you can recycle code written by others only make sure you are not going to write work arrounds to make that code work. Rather alter the "recycled" code to fix into you functional model using the functions and classes you defined. (U`ll see its not that difficult)

    Anywayz there are lots of things to consider. And most will crack you brain at first looking for the logical way of doing something. But it will be rewarding afterwards. Still do request tuts on that site, or look at They will help you with your code if help is needed ;)

    Good luck!

    Regards Chris
    LVL 2

    Author Comment

    I think you gave me some good material here.

    Maybe I will try to cut the features I wanted (for now) and try to keep my CMS simpler, in order to be able to easily switch from a template engine to another and see the differences.

    I was thinking to try Smarty, as I've already tried it, but I'm curious to learn also the phpBB template engine, if you tell me it's the "trade2.

    Smarty is used in Gallery2, which is one of my favorite open source projects: .

    Smarty has a built in cache system but I'm realy wondering how it works, it has to query the db or not...

    dutchclan: do you know any tutorials, online resources to learn about data modeling? In my case I don't need a big database. I need a small db just to store page content + eventually page categories and theri "childs". Basically the DB in my case has only 3 tables:

    1) pages
    2) categories
    3) categorychilds

    What about translations? I see some php scripts include a php file, which is quite easy to translate, but gallery2, wordpress and some other scripts use, instead, the .mo (.po format).

    Thanks for letting me know.
    LVL 5

    Assisted Solution

    Im sorry i cant help you with the "mo" "po" formatting, rather keep it to php/ inc / tpl myself so i wont confuse myself or others ;)

    as allready suggested, goto, its a friend of mine that is "writing" on the fly tutorials for everyone that requests them. So just request a tutorial on a specific subject and he`ll write it in a sec :)

    on the "logic" question.

    You can make it as complex as you want actually. for instance.

    table pages(
    id int unsigned not null auto_increment primary key,
    content_id int not null,
    title varchar() not null,
    css_file int not null,
    default_template int not null

    table css_files(
    id int unsigned not null aut_increment primary key,
    css_path varchar(100) not null,
    css_version varchar(10) not null,
    strict enum('1','0') not null

    table template_files(
    id int unsigned not null aut_increment primary key,
    template_path varchar(100) not null,
    html_version varchar(10) not null,
    strict enum('1','0') not null

    table content(
    id int unsigned not null auto_increment primary key,
    content_header largetext not null,
    content_footer largetext not null,
    content largetext not null

    now fir instance i have a table that forms my menu pointing to the ID of the pages, next that table points to various tables holding more specific data that i need to construct the page. But i can just as easly add a table catagories that point to pages that points to.... etc
    or another table catagory that points to the catagory_childs table that points to the pages table that points to .... etc

    Its all in your controll ;)

    And using smarty or the phpBB templating or the php Nuke templating... it doesnt matter as long as you think its usable for your site / project. Or use parts of the code that you render usable and rewrite a more "balanced" engine to your needs. But indeed its a nice way to learn, just dont copy paste and write it yourself. Get to know their logic and "why" they work so well. In a while you`ll be writing your own engine maybe surpassing theirs ;)

    Regards Chris

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now