views:

388

answers:

5

I've been developing in PHP for about 8 years as a hobby. In 2009, I picked up codeigniter and since then I've not managed to get a single project developed.

I find it slows me down trying to work out how to modify it to work the way I want, when if I was working in pure PHP, I'd know, or I'd be able to quickly find a snippet for.

I've tried CodeIgniter, Kohana and Symfony. I love the ease of use (and I've also started using doctrine as an ORM which massively sped up my database work), but I find projects are taking me 3-4 times the amount of time it took in pure PHP. I get bored and frustrated when I can't find a solution to a problem I've previously solved in pure PHP.

Has anyone gone back from using frameworks to a no-framework approach. Is there anything like a basic security framework (prevent XSS, filter posted data, provide a cleaning function for use with databases)? I think something like that would benefit me much more than a full scale framework. I think learning to work with frameworks has taught me a lot, but I'd be happier working with my own code.

+3  A: 

With that much experience behind you, you must have your own set of favorite libraries, hand pick them and come up with your own simple framework. Framework or no framework (and which one at that) depends on the kind of project at hand, no glove fits all. So i would strongly suggest that if you feel that the existing frameworks are slowing you down, spend sometime and come up with a framework which works as per your needs.

Sabeen Malik
+2  A: 

Zend Framework is really super for that. You can use as much or as little as you want. Its all coded in php and open sourced so you can just hack at it and make it your own. The different component are not dependant on eachothers as much as in other frameworks.

You could build yourself a simple framework using some components from Zend without any problems.

Check it out!

Iznogood
He is trying to move away from a framework.
WarmWaffles
@WarmWaffles. Wich is why I talked about using parts of ZF. Surelly you do not expect the guy to reinvent the wheel for everything.
Iznogood
Iznogood has a very good point. ZF is more than just a framework. I've found the packages to be extremely useful for doing a lot of common tasks, and there's nothing about it that forces you to use their MVC patterns or their DB access methods or really anything. Of course, you could just go with Pear modules, too.
Bob Baddeley
It is a library yes that also sports a framework. However he is looking for something easy to use, and last time I checked Zend's namespace is cluttered and a pain to type. @Bob_Baddeley PEAR is a good suggestion
WarmWaffles
@WarmWaffles Well to each his own I guess. Maybe you could recheck Zend its at 1.10.x now and pretty different then say 1.8.
Iznogood
+10  A: 

Current versions of PHP5 include much of the security framework you're looking for as part of the standard library.

If you're accepting HTML as input, I recommend grabbing HTML Purifier and calling it via a FILTER_CALLBACK line in your filter_input_array setup. Its whitelist-based approach to input security makes a great (and very powerful) first line of defense against XSS.

As far as I can tell, PHP doesn't come with a mechanism for protecting against cross-site request forgery, but I'm sure Google can help you with that one. The OWASP Security Cheatsheets include a section on it if you want to implement your own protection.

Out of curiosity, I decided to also start looking at standalone components and here's what I've found so far:

Templating:

  • PHP Template Inheritance (Regular PHP plus template inheritance)
  • TWIG (Django/Jinja2/Liquid-style syntax including autoescape and sandboxing. Compiles to cached PHP for speed.)
  • Dwoo (A faster, more featureful, PHP5-ish successor to Smarty. Includes a compatibility system for existing Smarty templates.)

Stuff I still haven't looked into properly:

  • Route dispatching (Only found RouteMap so far)
  • ORM (Just in case bare PDO isn't your thing)
ssokolow
Thanks, all very good advice and I'm going to start looking into them now!
Alex C
Swap out Smarty for Dwoo if you need a templating engine. Featurewise it's almost identical to Smarty but doesn't melt CPU's.
Phil Sturgeon
+1  A: 

For basic security, I use a custom filter method that wraps up my superglobals. Its syntax needs some getting used to, but is simpler than the PHP filter_var() API and doesn't let you slip sanitization:

 $_GET->text("inputvar") or $_POST->name["field"]

It also allowed inline $_REQUEST->sql() escaping. But for database work keep using parameterized SQL, or your DAL/ORM of choice.

mario
That's definitely a clever solution, but I'm not sure why you think the filter API is cumbersome. If anything, I think filter_input_array() is excellent. (Primarily because it makes it simple to define all the inputs for a given request type in one place in a reasonably declarative fashion. Never underestimate the benefit of that kind of thing.)
ssokolow
@ssokolow: Indeed, filter_input_array() is nifty for doing it in one swoop. However there is already too much flexibility in the filter_* functions, and too many parameters don't suit it. That's why I think people are eschewing it (even though it's technically a good solution).
mario
Perhaps. I think part of the problem is that, in addition to being a recent arrival in a world where a lot of people still have PHP4 books on their shelves, it's under-advertised, the official docs aren't clear enough, and the W3Schools docs which tend to share Google's top results aren't comprehensive enough.
ssokolow
+1  A: 

Based on your statement that you've been using PHP as a hobby, as well as your profile statement "Slowly getting there", this seems like a learning curve issue. You don't appear to have the depth and breadth of experience to a) understand how to work within the structure that the framework imposes and b) you are thus unable to benefit from the efficiencies that the framework enables.

I urge you to stick with it. Go back to the beginning with the video tutorials. Find and read other peoples code until you understand it. Build your projects from the bottom up - start simply, and add functionality. Follow the forums, trying to answer questions yourself before reading replies.

I've been programming professionally for almost 20 years, across a variety of platforms, and it still took me a while to become comfortable with CI. But now that I am, I wouldn't go back to pure PHP (for my own projects) unless I had a site of sufficient scale that it exposed quantifiable performance issues (think Twitter).

coolgeek
I'm still on the borderline whether or not I like frameworks too. I definitely see the OP's point, but I see yours too... learning a framework is like learning a whole new language. You have to get into the framework's way of doing things. Another thing that I struggle with, however, is if my philosophy of how things should be done is different than that of the framework. I'm still trying to find one that suits me. (Can't wait for .NET MVC3)
Mark
As yet, I don't know any other frameworks, so I can't speak with any generality. But using a framework isn't an all or nothing proposition. For instance, I find CI's caching libraries (page, database) insufficient and not readily scalable. So I use a third party cache library (Phil Sturgeon's) and I'm pretty happy with it.
coolgeek
Another significant advantage to sticking with it is that it makes it relatively easy to subsequently learn other frameworks. This is why you frequently see job listings specifying a particular framework (say, CI), but stating that experience with similar frameworks (say Zend, or Symfony) will be considered.
coolgeek