Reputation: 1116
I'm building a CMS using PHP and OOP - it's a bit of a learning project, something to improve my OOP skills while giving me the motivation of having a final target in mind.
I've come to actually coding the back end pages - I just have a question on how to best structure the app in terms of folders, files etc.
I have a folder of classes, some of which I plan to make use of in the front end website. One such class is the Page class which deals with loading the template (header, content and footer) which will work fine for the front end I'm sure. The back end is a different story however, obviously none of the pages (add/edit page, add/edit user etc) will be stored in the database so how should I handle the outputting of these pages?
Am I best creating sub classes of the Page class and setting the content up there? Or would it be better to create a new PHP file for each page? I'm leaning towards just using sub classes but that could lead to a pretty heavy file (Page class, sub classes of add page, edit page etc).
Any advice on the best way to go about this would be great.
Upvotes: 0
Views: 601
Reputation: 7900
I would do more or less this structure (MVC architectural pattern):
-MyCMS
--assets
----css
----img
----js
----templates
------pages
------partials
--------forms
--------grids
--conf
--src
----Controller
------Dispatcher
----Form
----Model
------DataMapper
----Routing
----View
------Renderer
--test
I think it is a bad idea to maintain all of your classes in the same folder, they should be grouped logically. This is just an example, you don't need to have these components in your src
folder, but will give you an idea of how to organize your componets.
Your class Page
should be generic, building a page from templates in assets/templates/pages
an not subclass it for each different page.
Upvotes: 1
Reputation: 5868
Put each sub-class into a separate file. Have the file name and the class name correspond, so you can set up class auto-loading later.
Upvotes: 1