Most of my experience is on the MSFT stack, but I am now working on a side project, helping someone with a personal site with cheap hosting that is built on the LAMP stack. My options for installing extras are limited, so I'm wondering about how to write my data access code without embedding raw queries in the .php files.
I like to keep things simple, even with .NET. I generally write stored procedures for everything, and I have a helper class that wraps all calls to execute procedures and return data sets. I'm not looking for a full-blown ORM, but it might be the way to go and others who view this question might be looking for that.
Remember that I'm on a $7/month GoDaddy account, so I'm limited to what's already installed in their basic package.
Edit: Thanks rix0rr, Alan, Anders, dragon, I will check all of those out. I edited the question to be more open to ORM solutions, since they are so popular.
ActiveRecord seems to be the state of the art at the moment. I can't recommend any good PHP frameworks for that though. I tried Propel which, while nice, is not easy to set up (especially on a host that you can't install anything on).
Ultimately, I rolled my own ORM/ActiveRecord framework, which is not too much work and very instructive. I'm sure other people can recommend good PHP frameworks.
Take a look at the Zend Framework, specifically Zend_Db. It has a Database Abstraction layer that doesn't require anything other than the MySQLi extension to be installed and isn't a full-blown ORM model.
Maybe Doctrine would do the job? It seems to be inspired by Hibernate.
rix0rrr hit on it a bit, in that many tools are a pain to set up. Of course, I have my own solution to this problem that has been working quite well for the past few years. It's a project called dbFacile
I also wrote a bit of a usage comparison of the tools I found a few years ago. It's incomplete, but might give you a good starting point.
You mentioned that you don't want to embed raw queries but you don't want ORM, so I'm a bit confused about the middle ground you're hoping to find. I also have an ORM project that aims to require minimal setup and great ease of use.
The only requirement for my projects is PHP5.
I would try a framework. Zend Framework has been cited. Symfony seems interesting. It's based on ideas from Ruby on Rails.
You could also take a look at Prado. http://www.pradosoft.com/ It uses Active Record and DAO. Also if you use .Net then some of the formatting and conventions are similar.
Related
I have been dabbling in programming/scripting languages since I was a kid. I started off with HTML and CSS, then went on to PHP (which I got quite good at) and then to Python, Perl, and C(++). I've recently done a lot of work in PHP (along with MySQL).
After spending so much time learning these languages, I now want to do something with them. I'm looking at starting/contributing to an open source project; almost certainly a web application of some sort.
In my experience with writing (admittedly small) web applications, I've found writing "pure" PHP to be an extremely slow and tedious process.
My question is this: if I were to be writing a relatively complex/large web application from scratch, what should I write it in? Should I use pure PHP/MySQL, or use a framework like Django, Rails, or CakePHP?
Writing a complex application from scratch, I would definitly not use "bare PHP" : I would certainly use a framework : they provide :
a large number of useful classes/methods
some set of rules -- like "in which directory should controllers be saved", "how to write a view", ...
MVC -- i.e. they help with better structuration of the project
Note that this answer is valid for both personnal projects, and professionnal projects.
There are several great Frameworks in PHP, like :
Zend Framework
Symfony
CakePHP
Code Igniter
Kohana
One thing to remember : learning how to use a framework well will take some time : starting with a small project, before going for a big one, would probably be a good idea ;-)
Now, when you're asking yourself the question of "which framework should I choose", it's mostly a matter of personnal preferences... And here are a couple of questions/answers that might help a bit :
PHP Framework Decision - Analysis paralysis!
To use a PHP framework or not?
PHP - MVC framework?
Which PHP Framework is right for this project?
Best PHP framework for an experienced PHP developer?
As you're asking me which Framework I would choose ; well :
I really like Zend Framework, and often use Doctrine as ORM (it's the default ORM of Symfony, but can be used very easily with ZF)
If I had to choose another one, I would probably go with Symfony, as I've seen it used on a couple of projects at work, and know many people who work with it and like it
If you already know that language, you should most definitely use a framework (unless you're a masochist).
For me, besides that fact that they're usually bundled with all sorts of great libraries, using a framework is all about using time effectively.
Most importantly, it will save you time. You're freed from the nitty-gritty of worrying about the foundation/architecture and are able to spend your time of the features of the application itself.
Also, it will save others time; especially since you plan on being all open sourcey.
depending of your skills level, yes you can do it in pure PHP without frameworks. This also will be good, IMO, to improve your skills at debugging, logics, and others. But, on the other hand, you will restrict to other programmers to improve/maintain your code due to learning curve, in this case, the framework serves as a commom language. I recommend that if your project will be complex, or with the possiblity to other programmers join in the project, that you choose a framework which you feels comfortable and use it.
Depends on who will be working with the code, on which plattform it has to run and how complex the database should be.
If you develop for a company or community it is always easiest to use PHP because there are many others who know it so i.e. for companies it's easier to recruit someone who knows the language.
If you mostly want to develop on your own, use what you like most, i even heard of websites written in pure common lisp.
If the application can run on windows only C# is also a good solution as you can develop web applications extremely fast and the .NET library makes many tasks easy.
As database backend you can use MySQL if the structure is simple but for more complex databases i'd use postgres as the MySQL performance seems to drop fast with increasing complexity (subjective opinion).
EDIT:
As others noted, Frameworks are always a good idea. There are web frameworks for most of the current languages. For PHP CakePHP was recently recommended to me.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
First, let me apologize for Yet Another Framework Question. But I think this is different enough from the usual "What framework should I choose?" to warrant it.
Here's my situation: For the past year I've been using a custom framework. It's been used on everything from small CMS's to larger sites and even a mid sized social network. It's worked great but I now see its limitations. So, I've decided to switch to a 3rd party framework. The simpler frameworks (CI, Kohana, Cake) seem too inflexible from what I've heard - so this led me towards ZF. But, I've also heard that ZF may be too flexible and thus hard to work with. What further complicates this is that I'm looking for a one-size-fits-all solution; I need a setup that works on small projects to very large projects. I am the main developer, but I need my partner to eventually be able to learn the system and help with the less complicated programming tasks.
I've researched Doctrine and I love it. So I'm leaning towards Symfony (with Doctrine) as the main framework with ZF to fill in the gaps. Plus, I need the ability to add my own pieces to this platform parallel to any 3rd party libraries. I hope this will provide me with a solid, extensible platform, as we really can't afford to be switching out frameworks every few projects.
I'm looking for advice from others who have been in the same situation as I am in now. Any advice would be greatly appreciated.
Edit: I've posted my solution below in hopes of helping other people in the same situation
After some research I've decided to go with Symfony. Here are my reasons:
Less verbose than ZF
Seems very customizable due to usage of YAML files (yet I never feel overwhelmed by them)
Autoloading of custom classes doesn't require any extra work like in ZF (albeit it's not hard to set up in ZF)
The developer toolbar is great, and they're adding some nice features to it in ver 1.3
The ability to use pieces from other frameworks (ZF, eZComponents) makes me feel confident that I won't have trouble finding what I need
Comes bundled with Doctrine and is very easy to set up (in fact Doctrine will become the default ORM in ver 1.3)
It seems like there's a much larger community for Symfony. Google "symfony tutorials" versus "zend framework tutorials" and you'll see a massive difference in the number of results
Plenty of documentation: tutorials (the Jobeet tutorial so far is very good), API references, and a more human readable description of the framework and its underlying principles
Yahoo! has used it for a few of their own projects - it's nice to see a Big Name back a framework IMHO
Edit: For the sake of hopefully helping others in the same situation, here are some things I don't like about Symfony:
Does not follow the PEAR naming scheme (ZF does)
Internal classes begin with "sf". This is contrary to the practice of capitalizing the first letter of the class name
Variables and functions are written_like_this, yet class methods are camelCased - this seems sloppy to me
These are all cosmetic issues though; things that bother me because I like to do things my way. I realize that whenever you use third party software you must be willing to make some sacrifices.
ZF is certainly a nice framework, but I feel using Symfony as the primary framework and extending it with pieces of ZF is the best choice for me and my team.
Edit
It's been 2 years since originally posting this, and since it's still getting hits I thought I'd give a quick update. I probably built about 25 - 30 projects using symfony 1.x in the last 2 years, and I'm very happy with how it performed. As a full stack MVC framework, partnered with Doctrine, it handled almost everything I threw at it. And whatever it couldn't handle, it was easy to add my own custom code. In fact, that's what I love most about symfony - how easy it is to extend. I ended up building a bunch of plugins and Doctrine behaviors that greatly reduced development time. And the admin generator tools have been a god-send. I'm still using symfony 1.4 for a few projects here and there, but have decided to mainly focus now on using Symfony2. It's a completely different beast than symfony 1, but I really appreciate its architecture. More importantly, it seems even easier to extend than symfony 1.x. I do miss some of 1.x's features, but that's the sacrafice you have to make when switching frameworks.
I like using ZF because of strong conventions. You can be sure, that everything will be as you expect it. Class names, function names, variable names, directory structure, ... all of it. It really speeds up the development if you stick to it. If you adapt it it's more like looking into your own code, when checking the ZF internals ;)
Let's be honest. ZF is not fast. Not as fast as Nette, CodeIgniter, etc. But the difference is that there is a class for everything. And if there is not, there is a class you can extend or interface you can implement.
All the other frameworks try to gain on the "wow" effect (blog in 30secs, twitter in 2 hours, etc). But when develioping a real life application, you realize, that it's the use at will, flexible and extensive architecture, that you need.
Zend Framework: Huge, Flexible, Modular.
I'd use only if am building a enterprise big ultra system.
But, I'm using Yii Framework and I like it.
Because: Very Fast, Simple, Widgets (easy to reuse component, this is very nice).
Yii it's easer to use, because is not a enterprise framework, and have all Basic features you really need in most cases.
*
EDIT: Now that I nearly understand HOW
to improve the ZendFramework using
your own code (as asked here Adding
3rd Party lib to Zend and here
Using 3rd Party lib within Zend),
I switched back to ZendFramework. I
currently design my application and
each day which I work and test
anything with ZendFramework it gets
more and more familiar and it easily
quickens my developement. My advise:
Use ZendFramework.
*
I have currently the same problem:
My story:
I was using CakePHP until I wanted to expand my project's size.
CakePHP was not as flexible as I wanted it to be.
So i tried to use ZendFramework.
The very first time I read the 'QuickStart' guide, i was a little bit afraid of having that much files for a simple guestbook application.
After a time of 'playing' with the ZendFramework I decided to use ZF as a 3rd party lib in my own custom framework.
The problem is, IF you use Zend's MVC components you might be forced to use 30% of the whole framework, because the MVC components are one of the biggest part of the ZF.
I mean if I use that much of a framework WHY shouldn't you use the rest, too?
After that, I decided to write my COMPLETE custom framework without using ZendFramework as 3rd party lib.
Now I am sitting in front of mountains of papers, full of sketches about code design.
I will keep you up to date about my further decisions.
I honestly think it really depends on your style. There's no end all be all answer to this question.
ZF relies heavily on classic and proven design principles. It's also very extensible, but requires more "configuration" than "convention". I personally do not trust 3rd party code by nature, so I'm a fan of more verbosity, for the sake of being more familiar with the technology I'm working with. But that's just me.
I've also used CakePHP successfully and two other frameworks proprietary to a company I worked for with great success. They're all trying to do similar things, just pick what feels best for you.
I've personally used CakePHP successfully for both large and small projects, however it is often difficult to make it budge the way you want. My reasons for using Cake continue to reside in the fact that the community support is top notch, the security updates are often, and they do not force meta-packages (such as unit testing) upon you (although this is bundled, you can just bin it if you're not interested in using the built in package).
Altogether, it's made a nice system for me over the past few months, however I have heard time and time again that Symphony is fantastic, so you may perhaps be on the money with your first thoughts. With NetBeans support for Symphony in the pipeline, I may too find the need to switch before long.
I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal.
What would be the best PHP framework
to use to build this quickly,
efficiently and with the smallest
learning curve?
I have narrowed down to CodeIgniter as the major contender for this project - but having looked through the docs I couldn't find a library or class that I can use with paypal - is the same for all frameworks- surley not?
Zend framework - I considered this but although its documentation is very good, hardly any video tutorials - other frameworks seem to have lots of these especially with normal developers creating screencasts - where is the Zend community!
CakePHP - Having read the stackoverflow threads, I gathered this is a slow framework, giving developers little control as it seems to be a CMS backbone rather than a framework - agree? It was also said cakePHP and Zend have a steeper learning curve than CodeIgnitor.
I have start my short-listing again and I would appreciate any help with this.
Thanks all
You'll very likely find CodeIgniter to have the lowest learning curve. Regardless of the framework you choose, you'll have to pick up where the framework leaves off, and that is going to mean a significant amount of work on your part (if you truly want to implement all the features of ebay). There seems to be a PayPal lib in the CodeIgniter Wiki. Looks like it would be a great place to start.
Cake is not a CMS backbone, it's a framework like the others. It's just more opinionated, i.e. geared towards CRUD operations (create, read, update, delete, what you typically do in a CMS). If your application is focused on CRUD, Cake will give your development a kickstart; you can get a complete admin interface for your database tables up in, literally, minutes.
Thanks to that it may be a little slower, especially compared to "loose" frameworks like Zend, but in the end it won't matter much. You can do anything with any of these frameworks and any of these frameworks can be optimized to run as fast as possible. Try to get a simple prototype app up and running in all of them and choose the one that seems most comfortable to you.
I'd really recommend Codeigniter for speed. I've made a few things with it and it was great.
If you need some help learning Codeigniter Nettuts has been doing some really good screencasts
In the end, it won't matter. Your code for database and presentation will trump any 'problems' your framework has. The frameworks you listed are awefully similar. You'll be more or less stuck with which you pick, so pick one and learn all you can.
If you're going with codeigniter (note, maybe take a look at Kohana too, the php5 fork of CI), you can always use libs out of Zend if theres something that fits your needs.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
What is the best method of understanding how and why a framework was written the way it was?
Develop a feature for it, or fix a bug. If you use the framework for developing a real-world solution, you can make a list of shortcomings to address or features to add that would make your task easier.
Fixing a bug will really help you understand the code, because most of the time you are given a piece of example code that recreates it, which you can then trace down into the bowels of hell to find where things go wrong.
All it takes is persistence, really.
Take a very simple component and analyze the code. For example, look at some of the components of the Zend Framework (something utterly simple like Zend_Version or, to step up a bit but still keep it simple, Zend_Debug). Pick them apart and see what makes them tick. Then, try to write your own simple component.
After making many websites 'from scratch' I found myself reusing the same scripts over and over, and I found some things tremendously tedious because I never bothered to abstract them away before for re-usability. So, if you have any experience making websites, you should have a pretty good feel for what your framework should include. If not, I would probably start by thinking of an MVC file structure, get your framework to first work with views, then controllers, then models. Then make sure each of those is easily extendable because no matter how hard you try, there will always be things missing... and then just start slapping on utilities as you need them (form helpers, model helpers, etc.). In other words, come up with a project for which you would like to use the framework, and build the framework and website concurrently.
I know the world needs another like it needs a hole in the head, but writing your own framework is a great way of learning a language. I wrote a fairly complete one in PHP in under a fortnight and learned a hell of a lot about PHP and Web development in the process.
The only reason I haven't released it is because I was finally not happy with the way it managed session state, but that was a good learning experience too!
I think the way to begin framework design is to write down about 5 basic aims for it. For mine, these were:
aimed at producing simple Web apps with a dozen or so forms
aimed at people with a good knowledge of SQL
no procedural code PHP or otherwise (except for that in SQL SPs)
no HTML/javascript/CSS programming needed
application described in XML
work on a vanilla PHP/Apache stack
no state maintenance on server
That was enough to get me started.
The other suggestion I can make is to try to build an app using the framewark at the same time as you build the framework itself. This will quickly reveal problems and suggest ideas for new directions abd features.
You are on the right track. Just remember that Rome wasn't built in one day. Every house is built over a longer period, brick by brick.
By using a framework, you will discover some of it'S shortcommings and be able to find some functionality that is missing or needs improvement.
Start there, develop the improvement and submit it to the frameworks community for peer review. Even if they decide not to include your work into the framework, you will receive very valuable feedback on your work.
Don't stop there, use what you learned in your first attempt for a second one (and a third, fourth, fifth...) That way you will learn to understand what others expect from the framework (which might differ very much from your own expectation), and slowly understand the inner workings of hte framework itself.
Conclusion: Be patient and persevere. Understanding will follow. (Sounds esoteric, I know. But it may work!)
There are a number of things that most frameworks include, although the definition is fuzzy.
Provide a basic bootstrapper (manage settings, setup environment, check for compatability issues between PHP versions, etc.)
URL Routing - How to define rules for which URLs point to which pages.
Manage plug-ins, libraries, modules, etc.
Database ORM - Manipulate objects instead of writing SQL queries (simplified)
Templating - Usually involves creating a mini-language for template logic (loops, conditionals) to avoid having PHP code in the template itself.
Beyond this, most frameworks also include a slew of libraries from simple e-mailing to advanced web service API's.
I would recommend two frameworks to look at:
Codeigniter
I recommend this because it's a "batteries included" framework that works out of the box. It also has a great community, lots of 3rd party libraries. CI has a bit of trickery to get the framework to play nice with both PHP4 and PHP5, which is also good to know (because, for some reason, a lot of people still use PHP5). You should also take a look at KohanaPHP, which is a branch of CodeIgniter that has been rewritten as a strict PHP5 framework.
Zend Framework
Zend is a module-based framework. Instead of dropping everything in a directory and churning out pages, you pick the parts you need and glue them together yourself. Since Zend is made by the folks behind the engine behind PHP (confused yet?) it uses "the latest and greatest" of PHP5 - everything is Objected-Oriented and it uses type hinting. Very clean code, if a bit verbose.
I think the essential stuff is the bootstrapper (the "glue" for the framework), as well as how each framework implements a system to support user-made libraries and plug-ins. The rest you can find as stand-alone applications elsewhere.
you should really try to understand, on a high level, the life cycle of a request. here's a good example a what happens from request to response in the Zend Framework, http://framework.zend.com/manual/en/zend.controller.basics.html
I'm new to the world of PHP frameworks and, after some initial investigation, came up with the following list of popular choices:
CakePHP
CodeIgniter
Symfony
Zend
I'm trying not to repeat the "Which is best?" question, which seems to elicit not much more than personal preference. Is this the case? Is one truly "better" than the other? What are the strengths and weaknesses of each?
I apologize if the question is too broad, but any clarification would be much appreciated.
The thing with frameworks is that they're perfect up to the point you need them to do something they're not made for.
I've worked with all of the major PHP framework's you've listed, except Zend and this is what I can quickly tell you:
CakePHP enforces OOP, gets you up and running quickly, has a great community and relatively good documentation, comes packed with all the features you'd come to expect.
CodeIgniter gives you the most elbowroom of the first three. Doesn't exactly enforce OOP, it leaves it up to you. The easiest to implement and distribute of the three. Fantastic community and they keep the documentation up-to-date with new releases. I like to consider it as a perfect skeleton for whatever you want to do, how you want to do it. Also, the most fastest of the three.
Symfony without a doubt, the most powerful of the three and the closest to RoR. Expect having to learn PEAR and have access to SSH on remote servers. Very slow and I wouldn't suggest it on shared hosts if you want to develop a big application. It does enforce some strange practices and you'll see more PHP in your views than you'd particularly rather like, but it has a tool to help you start working on a solution for every problem.
I stumbled across this (old) question as I am looking for a PHP framework that works well in a shared hosting environment ; speed is important as in shared hosting CPU time is the tightest constraint.