tags:

views:

86

answers:

3

So basically, this is what I have.

But is this a good practice? I started splitting up my admin.php file due to it growing in size.

However, I have a slight concern over how many files I could potentially end up with, and also problems to work with in case something may need to be updated over all the files.

A: 

Splitting on big file into a few smaller, more modular ones is always a good idea IMO.

However, looking at your code I would use a HTML templating engine in order to not mix up logic and presentation. Have a look at smarty.

Lenni
Although the idea of not mixing logic and presentation is a good one, I don't see a need to throw a template engine (smarty) on top of a perfectly good templating language (php)
Paolo Bergantino
I'd make a templating system if I could think of how to make the backend and frontends work together, because I don't know how.
a2h
@Paolo: Fair enough, however the one thing I hated about PHP was the scattered print statements all over the HTML. Do you know a way around this?@a2h: Well, you first gather together your variables and/or arrays and then call fill in the template, which has special tags like {{title}} with those variables.
Lenni
@Lenni - str_replace?
a2h
Yes, that'd be one way to write your own templating engine. As I said, you could use one that's already there and for PHP I like smarty because it is easy to learn and lets you do things like for-loops inside the template.
Lenni
+1  A: 

use classes in php, try to split your project into logical modules. Then you need not to make manual updates over all the files.

Sergey Kovalenko
+2  A: 

I had similar thoughts developing my own CMS engine. Eventually I end up with basicaly same solution as you did, but with Smarty, for logic-presentation separation.

But now after some time I have different and much better solution. Make use of Command Pattern. You will need to separate your code into classes not in files like you did. You must establish Command Interface which all of your classes will implement. This way your admin page will act as Front Controler (another design pattern).

Responsibilty of Front Controler is to gather all input from your page, that is in your case $_GET["action"] , according to this actions you will have to instantiate Command objects and after this switch statement you will call $command->execute(); that will execute code contained in your Command classes.

For your examle you will have : EditPageCommand, DeletePageCommand, NewPageCommand, etc.

Avoid code separation in files. Try to use classes for everything and learn patterns. ;)

zidane
I've never worked with classes before... :P
a2h
You should try... if you have any questions please ask...
zidane