tags:

views:

150

answers:

6

Hello folks,

I'm currently starting to write my own CMS in php from ground up using CakePHP (or should i use something else?) for my bachelors degree. And i'm thinking about various stuff that will be needed to do.

One of the things i can not figure out is if i should use a single file (for example, index.php will handle everything, and will include everything) or i should break up my cms into a few smaller files.

so my main questions are

  • is cakePHP a good choice?
  • use one file for everything or use multiple files?
  • do you have any good general advice on building more complex websites using php or any best-practices advice (i don't really understand why they don't teach us this in school)
+2  A: 

Using a single file "entry point" gives you more flexibility when it comes to routing requests to various logic - you'll only ever have to worry about filtering one spot in a request chain.

Amber
This pattern is called "front controller", very google:able
chelmertz
+1  A: 

These are really subjective questions.

I, once, wrote a CMS in php from ground up for my 3rd year project.

What I did was basically:

  • Checking how other people did it (Plume CMS and CMSmadesimple were a good start)
  • I didn't use any framework (that was a requirement)
  • and Yes, I used index.php with multiple params to handle different pages.
Soufiane Hassou
i will also take some inspiration from allready existing cmses. and i can use any framework, luckyly. and to this day i also used inex.php as the entry point of my projects... but i was just wondering how other people feel about this and/or if there is a better way
Gabriel
+3  A: 

Using a single entry point or multiple entry points becomes a moot point if you are using most frameworks. CakePHP for instance has an index.php file and all you end up doing is defining models, views, and controllers for different parts of your project. I would imagine that most frameworks these days work this way.

Alternatively, if you choose to roll your own framework and system for managing this, which given this is for a bachelor's degree may be (1) a lot of extra work but (2) more revealing and more instructive, I can speak from experience that I found having a single entry point to be useful.

  1. It enables you to have a common code path for set-up stuff: things like enabling E_STRICT, E_NOTICE, etc. for debugging and reliability purposes. Things like sanitizing form inputs to work around the magic-quotes setting. Yes you can do that from an include 'globals.php' but:

  2. Putting everything in one place also lets you come up with a standard file-naming convention and an __autoload handler that will help remove any include or require directives except for perhaps one. Means you can add classes and such without having to also remember to update a master file.

  3. And this is entirely subjective, but I have found that it's easier to create simpler URLs using this. Instead of /volunteers/communities.php?id=Hedrick_Summit I can do /volunteers/communities/Hedrick_Summit which is more pleasing to me.

As for the choice of CakePHP, I have briefly toyed around with that framework. What I don't like about frameworks in general is they often have to be too general, to the point it results in extra cruft and slower page rendering. And the moment you have to do something that pushes the boundaries of the framework, and you will, you end up fighting the framework.

But to be fair, CakePHP seems to be adequate and generally well-designed. I personally took issue with the ORM layer but that was me striving for perfection and actually trying to do work in the SQL query. It has a reputation for being slow, but unless you're trying to build the next Facebook you should be fine.

Michael
A: 

Answer is yes use multiple files in multiple directories, it makes all difference in the world when you need to debug or scale.

aromawebdesign.com
oh and regarding cackePHP, I personally wouldn't use any framework, it is really hard to learn how PHP actually works using the frameworks, that does most of the ground work for you.
aromawebdesign.com
since i know quite well how php works (programming in it for like 3 years) and i never used any kind of framework i woul like to try one, and see how it will work out
Gabriel
A: 

I would advise you to keep in mind the MVC (Model-View-Controller) pattern. It is one of the most commonly used (and often misused) patterns in the CMS field.

Also, don't be afraid about looking what other people are doing. Read the code from Joomla, Drupal and other open source CMS. Have a look to language different from PHP to have a comprehensive glance about the possibilities.

Don't try to simply re-invent the wheel. Even if this is simply a Uni assignment, try to put something new on your CMS. Something that would push me to use yours instead of other CMS.

Roberto Aloi
i want to stick to php because of various reasons (most hosings support php etc etc) and certainly i will not reinvent the wheel. but as you said, i want to create something that would potentionaly atract people.also i'm planning releasing it as open source
Gabriel
A: 

is cakePHP a good choice?

That's a highly subjective question and as such unanswerable. Though, if you want to experiment with architecture (eg. compare front controllers to page controllers), you probably should build more from scratch, as a lot of those decisions have already been made by the writers of said framework (And a lot of other frameworks, for the matter).

use one file for everything or use multiple files?

It's called a front controller (single entrypoint) or page controllers (multiple entry points). Get a copy of Patterns of Enterprise Application Architecture by M. Fowler.

do you have any good general advice on building more complex websites using php or any best-practices advice (i don't really understand why they don't teach us this in school)

There are billions of CMS's. Find some of them and analyse them to find out what they did and how they differ from each other. Trying to categorise the different approaches and compare their strenghts/weaknesses could make for a good paper.

troelskn