Reputation: 49
Over the last 18 months i have been hard at work teaching myself PHP & Jquery and so far have become quite good at it but not having a "mentor" i have developed my own "model" for building webapps / sites. it goes like this...
I have my front end page (HTML) and a js script which i fill with lots of jquery ajax (using a get or post method then pass on a command to the php) commands which in turn reference a sometimes large php file made up almost entirley of one big "switch / case" command with all my various options.
my question is this, is there a better way to do this?
i want to advance in my skills, where should i take my model next?
Upvotes: 1
Views: 202
Reputation: 3034
In your case I would make the switch to Object Oriented Programming. I've been in a similar situation like you but wasn't satisfied anymore at how my websites looked with simple procedural scripting. Switching to OOP will take quite some time to get used to, but in my opinion it was all well worth the effort.
Take your time learning OOP. First, check http://www.php.net/ to learn about objects and classes and afterwards read a book on the subject (Php Objects, Patterns And Practice by Matt Zandstra is a very good one http://www.amazon.com/PHP-5-Objects-Patterns-Practice/dp/1590593804). You will find out why a lot of people have made a switch to the OOP approach for web apps.
When you are used to the way of thinking in OOP, choose a framework. It doesn't make sense to write code for things that have been written 100 times before and are tried and tested approaches to common problems. A framework covers all the basic annoying stuff you shouldn't be spending your precious time on. But only choose a framework when you have really grasped the way of thinking with OOP. It's always best to learn the basics first instead of jumping right in the middle by directly choosing a framework.
Upvotes: 0
Reputation: 21231
To put it simply: start learning the pros and cons of the various programming patterns. Sounds like you're doing Front Controller, which is fine for simple, one-off projects. The GoF book, Design Patterns, is supposed to be really good. A friend of mine really likes the Head First version...
Upvotes: 1
Reputation: 3848
"is there a better way to do this?" What is this? Structure code? Achieve asynchronous updates on individual widgets on a page? Not have giant and potentially unmaintainable blobs of gunk?
Consider exploring CodeIgniter to move more in the direction of web application development.
Upvotes: 0
Reputation: 50976
To be honest, I do the similar.
I have one file, index.php or so, and urls looks like this
index.php?what=faq
index.php?what=news
....
and I use switch{}
case: break;
commands
and it looks like this
switch($_GET['what']){
case "faq":
include("Templates/faq.php");
break;
case "news":
include("Templates/news_v2.php");
break;
}
so just a tip: do not proccess any code in cases, just include your template file and do everything there
Upvotes: 0