How to make coding php easier?
November 1, 2009 10:57 AM Subscribe
I'm about to start on a medium sized php project and am looking for some ways to make things easier on myself. I would like to avoid frameworks. I've used cakephp before and found too many frustrating obstacles. I was considering codeignighter this time around, but am worried that it will just be more of the same. What I'm trying to avoid is my normal hodgepodge of code and would like to find some libraries and organization structure for my code. Any suggestions?
You could write your own mini-framework. I wrote my own framework but for smaller jobs or where going the full MVC hog is inappropriate I just use the database and model classes.
It really doesn't take long to do either - I wrote the basics of my framework in a weekend and that included an installer to generate the forms, models and controllers.
posted by missmagenta at 11:27 AM on November 1, 2009
It really doesn't take long to do either - I wrote the basics of my framework in a weekend and that included an installer to generate the forms, models and controllers.
posted by missmagenta at 11:27 AM on November 1, 2009
Response by poster: The client sells coaching and lessons via their website. The site will have CMS ability for some sections (but not all) on the front end and E-commerce for purchasing the lesson packages. The majority of the project is on the back end where the client will schedule lessons, fill out evaluations, view reports, communicate with students. Basically manage the business. Much of the same functionality should be available for students to view their progress in their dashboards in a member area.
What i didn't like about cakephp was that I found it difficult to do complex queries with multiple joins, or grab some data that wasn't in the model. Granted most of these problems arose because of poor planning up front by the client in determining what they wanted the site to do, so I was constantly having to hack things together to add new features that didn't fit into the original structure. It kind of left me feeling confined.
posted by funkyavocado at 12:35 PM on November 1, 2009
What i didn't like about cakephp was that I found it difficult to do complex queries with multiple joins, or grab some data that wasn't in the model. Granted most of these problems arose because of poor planning up front by the client in determining what they wanted the site to do, so I was constantly having to hack things together to add new features that didn't fit into the original structure. It kind of left me feeling confined.
posted by funkyavocado at 12:35 PM on November 1, 2009
Maybe something like spoon is up your alley? It's not a framework but does give you a lot of useful, already documented libraries.
posted by shownomercy at 12:55 PM on November 1, 2009 [1 favorite]
posted by shownomercy at 12:55 PM on November 1, 2009 [1 favorite]
The client sells coaching and lessons via their website. The site will have CMS ability for some sections (but not all) on the front end and E-commerce for purchasing the lesson packages. The majority of the project is on the back end where the client will schedule lessons, fill out evaluations, view reports, communicate with students. Basically manage the business. Much of the same functionality should be available for students to view their progress in their dashboards in a member area.
Hmm...without knowing too much of the details of this, this seems like a pretty vanilla administration site, and something that would generate a lot of the CRUD for you I would imagine could be quite helpful. Certainly, my inclination would be to start with a MVC framework if at all possible.
What i didn't like about cakephp was that I found it difficult to do complex queries with multiple joins, or grab some data that wasn't in the model. Granted most of these problems arose because of poor planning up front by the client in determining what they wanted the site to do, so I was constantly having to hack things together to add new features that didn't fit into the original structure. It kind of left me feeling confined.
Ah...so it sounds like your issues are more with using an ORM rather than the overall framework, huh? Well, the ORM that Symfony uses, Propel, seemed pretty flexible to me--it has a decent syntax and lets you do a fair amount of SQL-ish things even using an OO framework. For examples in the Ruby world, check out ActiveRecord and Datamapper, just to name two of the more popular ones.
But, fundamentally, if you are a developer who is used to doing a lot of work in SQL, shifting your mentality to an ORM takes some doing. You have to shift your perspective on what gets done where and how it gets done. I'm not saying one is better than the other, and in fact I bemoan the fact that my SQL chops have gotten somewhat weaker in the last few years--which is at least partially due to using ORMs as a matter of course--but I believe the time I've saved and productivity I've gained overall have been worth it. So, that's my ORM spiel. It is what it is, and it gets better all the time as the software matures, and different strategies are explored
Also, to try to address some of the specific issues you listed: a decent framework will make it relative easy to add new data to the model after the fact, and re-deploy without wiping your DB. You acknowledge that your clients gave you some difficult hurdles because of some poor planning, but you should have ways to get around a lot of these kinds of issues relatively painlessly with a decent framework.
You could write your own mini-framework. I wrote my own framework but for smaller jobs or where going the full MVC hog is inappropriate I just use the database and model classes.
missmagenta, maybe I'm old and lazy, but this just seems like too much of a pain in the butt to me when there are so many frameworks out there. ;)
Seriously though, I think that, unless you have very specific design constraints to contend with, (again I say) most web app "problems" in this world have been "solved" already. I strongly believe there's no point in reinventing the wheel.
I hope this is helpful--I'm not trying to be roundabout or vague, but I think some of your concerns could be dealt with by shopping around a bit and seeing what else is out there. Having increased my familiarity with MVC frameworks in the last 3-5 years I've realized that, generally speaking, I do a lot less work now, and can concentrate on the interesting stuff.
posted by dubitable at 1:11 PM on November 1, 2009
Hmm...without knowing too much of the details of this, this seems like a pretty vanilla administration site, and something that would generate a lot of the CRUD for you I would imagine could be quite helpful. Certainly, my inclination would be to start with a MVC framework if at all possible.
What i didn't like about cakephp was that I found it difficult to do complex queries with multiple joins, or grab some data that wasn't in the model. Granted most of these problems arose because of poor planning up front by the client in determining what they wanted the site to do, so I was constantly having to hack things together to add new features that didn't fit into the original structure. It kind of left me feeling confined.
Ah...so it sounds like your issues are more with using an ORM rather than the overall framework, huh? Well, the ORM that Symfony uses, Propel, seemed pretty flexible to me--it has a decent syntax and lets you do a fair amount of SQL-ish things even using an OO framework. For examples in the Ruby world, check out ActiveRecord and Datamapper, just to name two of the more popular ones.
But, fundamentally, if you are a developer who is used to doing a lot of work in SQL, shifting your mentality to an ORM takes some doing. You have to shift your perspective on what gets done where and how it gets done. I'm not saying one is better than the other, and in fact I bemoan the fact that my SQL chops have gotten somewhat weaker in the last few years--which is at least partially due to using ORMs as a matter of course--but I believe the time I've saved and productivity I've gained overall have been worth it. So, that's my ORM spiel. It is what it is, and it gets better all the time as the software matures, and different strategies are explored
Also, to try to address some of the specific issues you listed: a decent framework will make it relative easy to add new data to the model after the fact, and re-deploy without wiping your DB. You acknowledge that your clients gave you some difficult hurdles because of some poor planning, but you should have ways to get around a lot of these kinds of issues relatively painlessly with a decent framework.
You could write your own mini-framework. I wrote my own framework but for smaller jobs or where going the full MVC hog is inappropriate I just use the database and model classes.
missmagenta, maybe I'm old and lazy, but this just seems like too much of a pain in the butt to me when there are so many frameworks out there. ;)
Seriously though, I think that, unless you have very specific design constraints to contend with, (again I say) most web app "problems" in this world have been "solved" already. I strongly believe there's no point in reinventing the wheel.
I hope this is helpful--I'm not trying to be roundabout or vague, but I think some of your concerns could be dealt with by shopping around a bit and seeing what else is out there. Having increased my familiarity with MVC frameworks in the last 3-5 years I've realized that, generally speaking, I do a lot less work now, and can concentrate on the interesting stuff.
posted by dubitable at 1:11 PM on November 1, 2009
Response by poster: Thanks for all the advice. You seem to favor Symfony. Do you have any experience with codeigniter. Any pros/cons for each?
posted by funkyavocado at 1:41 PM on November 1, 2009
posted by funkyavocado at 1:41 PM on November 1, 2009
Thanks for all the advice. You seem to favor Symfony. Do you have any experience with codeigniter. Any pros/cons for each?
To be honest, I only favor Symfony because it's the only PHP framework I'm at all familiar with. I'm much more familiar with Ruby MVC at this point, I'm afraid. My advice is certainly about these things as a general class vs. specific frameworks or libraries. What I can tell you about Symfony (again, at v 1.1, last time I used it) is that I didn't care for the Forms system, thought the model features were pretty decent, and thought the filtering and configuration were generally pretty nice. It makes you write your model definition in YAML and then generates the classes/SQL from there, if I recall, as opposed to how Merb does it where it's more or less the other way around.
All that aside, let me take a look at these and see if I can offer any further advice based on what I already know...but take it as a given that advice from someone with real experience with cakephp and codeigniter will probably trump whatever I can suggest...more soon.
posted by dubitable at 1:48 PM on November 1, 2009
To be honest, I only favor Symfony because it's the only PHP framework I'm at all familiar with. I'm much more familiar with Ruby MVC at this point, I'm afraid. My advice is certainly about these things as a general class vs. specific frameworks or libraries. What I can tell you about Symfony (again, at v 1.1, last time I used it) is that I didn't care for the Forms system, thought the model features were pretty decent, and thought the filtering and configuration were generally pretty nice. It makes you write your model definition in YAML and then generates the classes/SQL from there, if I recall, as opposed to how Merb does it where it's more or less the other way around.
All that aside, let me take a look at these and see if I can offer any further advice based on what I already know...but take it as a given that advice from someone with real experience with cakephp and codeigniter will probably trump whatever I can suggest...more soon.
posted by dubitable at 1:48 PM on November 1, 2009
I've built a couple large scale e-commerce sites with codeigniter, including one that had an extensive backend allowing for workflow management of an audio production team.
You probably also want to check out the commercial version of CI, expression engine as it has some features geared towards blog/cms/e-commerce you might find useful.
posted by zentrification at 2:20 PM on November 1, 2009
You probably also want to check out the commercial version of CI, expression engine as it has some features geared towards blog/cms/e-commerce you might find useful.
posted by zentrification at 2:20 PM on November 1, 2009
Response by poster: Thanks,
I have used EE before and liked it, but I think I will need to build something more custom in this case.
Would anyone recommend Smarty. Since it's not a framework, would it be a good middle ground?
posted by funkyavocado at 2:30 PM on November 1, 2009
I have used EE before and liked it, but I think I will need to build something more custom in this case.
Would anyone recommend Smarty. Since it's not a framework, would it be a good middle ground?
posted by funkyavocado at 2:30 PM on November 1, 2009
Would anyone recommend Smarty.
Please, please, please do not put a templating system on top of what is essentially a templating language in lieu of using or creating a real framework.
IMO, the only acceptable use for Smarty is as a way to keep designers from having to learn PHP. If you're already coding in php, there's absolutely no reason I've ever seen to use a templating system like smarty.
It's not a framework, it's just extra bloat because you're essentially recreating PHP's core functionality in a less efficient way.
Use the features of CI or Cake or Symfony that you want. Scrap the rest.
posted by toomuchpete at 2:39 PM on November 1, 2009
Please, please, please do not put a templating system on top of what is essentially a templating language in lieu of using or creating a real framework.
IMO, the only acceptable use for Smarty is as a way to keep designers from having to learn PHP. If you're already coding in php, there's absolutely no reason I've ever seen to use a templating system like smarty.
It's not a framework, it's just extra bloat because you're essentially recreating PHP's core functionality in a less efficient way.
Use the features of CI or Cake or Symfony that you want. Scrap the rest.
posted by toomuchpete at 2:39 PM on November 1, 2009
I would rather chew my own leg off than work with Smarty again. Similar feelings about CI.
Zend Framework. It's got a good shot at becoming the de facto PHP framework, and it's constructed more like a library, so it will get out of your way when necessary, and the learning curve is a bit shallower (you can pull in single components like Zend_Registry or Zend_Acl without committing to the entire framework).
For the ORM stuff I've heard good things about Doctrine, but I haven't used it myself.
At some point you just have to bite the bullet and learn one of these tools. You'll take a performance hit on the project you use for learning, but after that...
posted by Leon at 3:01 PM on November 1, 2009
Zend Framework. It's got a good shot at becoming the de facto PHP framework, and it's constructed more like a library, so it will get out of your way when necessary, and the learning curve is a bit shallower (you can pull in single components like Zend_Registry or Zend_Acl without committing to the entire framework).
For the ORM stuff I've heard good things about Doctrine, but I haven't used it myself.
At some point you just have to bite the bullet and learn one of these tools. You'll take a performance hit on the project you use for learning, but after that...
posted by Leon at 3:01 PM on November 1, 2009
missmagenta, maybe I'm old and lazy, but this just seems like too much of a pain in the butt to me when there are so many frameworks out there. ;)
Well I didn't know about them at the time :p I'd started learning ruby on rails and I loved rails, ruby not so much so I decided to emulate all the rails stuff that I like with php. After I'd done it ofcourse I found out there are like a hundred already out there but honestly I still prefer mine to the ones I've tried and I didn't become a programmer to let someone else have all the fun ;) You learn a lot by writing your own stuff.
posted by missmagenta at 12:39 AM on November 2, 2009
Well I didn't know about them at the time :p I'd started learning ruby on rails and I loved rails, ruby not so much so I decided to emulate all the rails stuff that I like with php. After I'd done it ofcourse I found out there are like a hundred already out there but honestly I still prefer mine to the ones I've tried and I didn't become a programmer to let someone else have all the fun ;) You learn a lot by writing your own stuff.
posted by missmagenta at 12:39 AM on November 2, 2009
Well I didn't know about them at the time :p I'd started learning ruby on rails and I loved rails, ruby not so much so I decided to emulate all the rails stuff that I like with php. After I'd done it ofcourse I found out there are like a hundred already out there but honestly I still prefer mine to the ones I've tried and I didn't become a programmer to let someone else have all the fun ;) You learn a lot by writing your own stuff.
Fair enough, those are all reasonable points!
I guess it just depends on your goals in the end.
posted by dubitable at 12:34 PM on November 3, 2009
Fair enough, those are all reasonable points!
I guess it just depends on your goals in the end.
posted by dubitable at 12:34 PM on November 3, 2009
This thread is closed to new comments.
In my experience, in this day and age, it really doesn't make sense to build the scaffolding for the vast majority of web applications. You can take or leave as much of a framework as you need, depending on how well the framework was built and how much it ties you in, and how much you need. For example, (while I despise PHP with a passion,) I've used Symfony (http://www.symfony-project.org/) with some success--although I thought the Form building system was really unwieldy (at least in the deprecated v. 1.1 which was the last one I used). But I can think of ways to use Symfony without using the Form building system--or using a minimal sub-set of its features, if need be. On the other hand, now I'm working with Merb (soon to be Rails 3) and I love it--it is quite minimal. While that means I have to build more of some things, it still saves me a lot of time because what it does provide is well thought out, generally.
So, yeah, I need more information to help. What do you need to build, what would you rather not build?
posted by dubitable at 11:17 AM on November 1, 2009