suggestions to develop my own (simple) CMS

Posted on 2006-05-18
Medium Priority
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 ( http://www.jvmultimedia.com/portal/node/6 ). 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
  • 2

Assisted Solution

aminerd earned 600 total points
ID: 16715552
> 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.

Accepted Solution

dutchclan earned 1000 total points
ID: 16717203
>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 (http://www.rabiddog.co.za).

> 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, www.rabiddog.co.za or look at www.ozzu.com They will help you with your code if help is needed ;)

Good luck!

Regards Chris

Author Comment

ID: 16719776
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: http://gallery.menalto.com .

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.

Assisted Solution

dutchclan earned 1000 total points
ID: 16720471
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 rabiddog.co.za, 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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