Hi there,
I've always created normal HTML/CSS websites and since I started using PHP for some simple stuff like guestbooks/news scripts/login script etc...
I have decided I would like to write (first a simple) backend system that I would just have to implement in future site I create so that my clients could customize their site through my own system.
The problem is that people say (and google) says almost all the time that it's best to use a framework build with de MVC pattern.
I think writing this MVC framework is a bit to difficult for my level of PHP writing at this time.
Can someone help me with this? Should I just learn an existing framework to build my backend on or what should I do?
Creating a reusable backend
Started by Coldhearth, Dec 06 2008 11:05 AM
17 replies to this topic
#1
Posted 06 December 2008 - 11:05 AM
|
|
|
#2
Posted 06 December 2008 - 01:41 PM
#3
Posted 06 December 2008 - 02:38 PM
I know some Java yes :) but I'm certainly no expert that's for sure...
#4
Posted 06 December 2008 - 03:49 PM
Before I started building my backend/cms I took the time to garner a solid understanding OOP, how it works with PHP, and several design patterns including the MVC. That said, I would recommend taking the time to advance to this level as it will save you time in the long run.
I would venture to say it is near impossible to create a procedural backend that will have seamless integration with your future websites. You will most likely resort to recreating the entire backend each new site you implement. With good OOP practice and an MVC design, this is not an issue.
I would venture to say it is near impossible to create a procedural backend that will have seamless integration with your future websites. You will most likely resort to recreating the entire backend each new site you implement. With good OOP practice and an MVC design, this is not an issue.
#5
Posted 07 December 2008 - 03:39 AM
Okay :) so can you give me any good resources or books that you used for example to learn about these subjects...? That would be realy helpfull :)
So maybe it's better to start designing stuff like a normal news script but in the OOP way of PHP rather than the procedural way? And by doing this learning the OOP of PHP and advancing to a higher level of understanding before building a backend/CMS
So maybe it's better to start designing stuff like a normal news script but in the OOP way of PHP rather than the procedural way? And by doing this learning the OOP of PHP and advancing to a higher level of understanding before building a backend/CMS
#6
Posted 07 December 2008 - 04:55 AM
One way to get a better understanding of OOP is to find aspects of web design that you would like to use without seeing the ugly details every time. For example, in ASP, text form submissions, binary form submissions, and address-bar parameters are accessed in three completely different ways. Creating an OOP wrapper for that (obviously a different situation, but a good example) is a nice way to improve your understanding of OOP AND make your life easier.
I'd give more examples in PHP, but I don't know it that well myself.
I'd give more examples in PHP, but I don't know it that well myself.
#7
Guest_Jordan_*
Posted 07 December 2008 - 05:54 AM
Guest_Jordan_*
Coldhearth said:
Okay :) so can you give me any good resources or books that you used for example to learn about these subjects...? That would be realy helpfull :)
Two great books for PHP OOP:
Amazon.com: Pro PHP: Patterns, Frameworks, Testing and More (Pro): Kevin McArthur: Books
Amazon.com: PHP Objects, Patterns, and Practice, Second Edition: Matt Zandstra: Books
#8
Posted 07 December 2008 - 06:21 AM
Okay thx I'll look those up and also try to look for some OOP based PHP scripts on the internet to get a better view on this.
I already know some OOP but the problem I keep having is that I know my theory but when I have to start a project lets say something simple as a guestbook, I never know how to start, wish classes to use etc...
I think that's one of my biggest problems... and I don't realy know how to get rid of this (I have read a lot about OOP but to do something like that myself from the beginning keeps bothering me... :( )
I already know some OOP but the problem I keep having is that I know my theory but when I have to start a project lets say something simple as a guestbook, I never know how to start, wish classes to use etc...
I think that's one of my biggest problems... and I don't realy know how to get rid of this (I have read a lot about OOP but to do something like that myself from the beginning keeps bothering me... :( )
#9
Guest_Jordan_*
Posted 07 December 2008 - 06:30 AM
Guest_Jordan_*
The second book in that list above describes when and where to use OOP in PHP very well.
When I create an MVC pattern just about everything except the controller is a class/object. That is not to say that the controller could not be a class as well. I prefer the use of a factory in the model which creates child models (based on an abstract class) and returns a view object upon execution to the view. Passing around objects allows me to create many different view objects (XML, HTML, Mobile, etc.) which all act in the same way. When the view (in MVC) receives this object it can always depend on the object acting in the same method. Basically, this makes for clean code that is easy to modulate. There may be a lot of up-front work but 2 months later when you need to add a new view (JSON, for example) your code will be easily extendible.
Both books above explain MVC fairly well with PHP.
When I create an MVC pattern just about everything except the controller is a class/object. That is not to say that the controller could not be a class as well. I prefer the use of a factory in the model which creates child models (based on an abstract class) and returns a view object upon execution to the view. Passing around objects allows me to create many different view objects (XML, HTML, Mobile, etc.) which all act in the same way. When the view (in MVC) receives this object it can always depend on the object acting in the same method. Basically, this makes for clean code that is easy to modulate. There may be a lot of up-front work but 2 months later when you need to add a new view (JSON, for example) your code will be easily extendible.
Both books above explain MVC fairly well with PHP.
#10
Posted 07 December 2008 - 06:40 AM
One of the other problems most books on OOP have is they tend to get you thinking you need OOP for EVERYTHING! The reality tends to be very different. I use a mixture of OOP and procedural programming. I use OOP to encapsulate certain things in a handy package. Some things are specific to what you're doing and no amount of OOP will make your code reusable.
#11
Posted 07 December 2008 - 07:03 AM
Hmz I guess I'll need to practice a lot... I would realy want to learn this because I want to start writing my own framework and CMS... this is my goal... Hope I can achieve it :)
#12
Guest_Jordan_*
Posted 07 December 2008 - 07:04 AM
Guest_Jordan_*
What WingedPanther states is very true. Both of those books will tell you to refractor your code to the point of oblivion. There are logical places to use objects and you'll learn when/where.


Sign In
Create Account


Back to top









