views:

1759

answers:

10

I've started writing quite a few applications in PHP mainly for Wordpress and becoming more and more familiar with the language.

Someone told me about CakePHP and Codeigniter and I wanted to get a better understanding of how these could help me and whether it's worthwhile spending the time to learn a framework?

Thanks

Jonathan

+22  A: 

My philosophy is that you should only use something when it solves a need that you currently have.

There's a real tendency, particularly in this realm, to simply use a framework for the sake of using one or because you feel like you should be using something. I discourage such practices. Also frameworks I think have the most value when you've done things the hard way so you have a good understanding of what problems you have and how the framework can help you in that situation. Framework choice does depend on the situation.

That all being said, the MVC pattern with Web applications is useful so it certainly wouldn't hurt you to learn at least one. I'd stick to a fairly minimalist framework however. CodeIgniter springs to mind here.

Lastly, the other danger with frameworks is that they can be so invasive that you're no longer doing PHP, you're doing CakePHP, Symfony or whatever. That's not necessarily a problem but the danger in it being so invasive is you don't get a good grounding in PHP and if you ever want to change it'll simply be too hard that you'll never be able to do it.

cletus
Bart van Heukelom
I strongly agree on your view. I share the same philosophy as yours. I do see people who can only code in a framework slang of a language. If he/she leaves the framework and configuration files, hands up. I personally try not to use any framework for simple stuff and a minimal one that I can still assume what happen inside if I have to use one. And a complex one only if I need to do something very standard and I expect nothing odd will come up and want it really quick.
ttchong
+16  A: 

What are the benefits of using MVC PHP frameworks ?

Well there are many benefits of using PHP frameworks, let’s see some of the main benefits of using them.

  1. They PHP frameworks follows some design pattern, so when you use these framework you’ve to follow their coding convention which makes your code clean and extensible for future purpose.
  2. The Popular PHP frameworks like CakePHP, CodeIgniter, Zend Framework , Symfony follows Model View Controller(MVC) design pattern which separates business logic from user interface making the code cleaner and extensible.
  3. As everybody can guess, these frameworks contains a lot of libraries to make your job easier. For example, to validate a from you don’t have write much code as you’ve to in normal coding scenario, just few lines of code calling the library might be enough for it.
  4. While working on a large project in a team, these MVC PHP framework will be a great tool for development as you can assign a developer to develop MVC part of a module for a developer and integration will be quite easy of these developed module at final level.
  5. These MVC framework will really helps you to develop the project rapidly, if you know one framework well then you’ll never worry about the project deadline.
  6. Most of these MVC frameworks uses clear url approach making your web project SEO friendly.

check article

Adinochestva
Apart from point 3, all of your bullet points can equally well be achieved without a framework.
Jacco
you can walk to your destination , you will arrive there but i prefer to use my car
Adinochestva
Not really--not unless you write your own MVC framework, which is still a framework. And even if you could implement the MVC pattern without a framework (your own or otherwise), why would you want to? Unless you're just dabbling in PHP web development and won't ever touch PHP after this one project, you will want to be able to re-use a lot of your code, like routing, ORM, session management, security, etc. You might be able to make a painting without a paintbrush, but that doesn't mean using the right tools for the job doesn't have its benefits.
Calvin
^My previous comment was in response to Jacco
Calvin
+3  A: 

One of the great perks of PHP frameworks are that they minimize reinventing the wheel in a great number of common web application needs. Security issues, graceful exception handling, RESTful URLs, and reusability of code across your site are fairly universal considerations.

It may be easier to familiarize yourself with the tools of a framework and then see if you want to take on the full MVC system it supports. For that end, I'd suggest familiarizing yourself with the Zend Framework. ZF works as a library of classes which can be implemented individually for particular uses--anything from security to Lucene search--but contains classes which, when used together, implement a fully fleshed out MVC paradigm.

Robert Elwell
+3  A: 

I think it's undoubtedly a good investment to spend the time to learn a PHP framework. For one, it'll teach you how someone has tackled the problem of architecting the framework, how to organize your PHP code, and how to handle things like sessions and database accesses...etc...

For the most part, if you are serious about developing web-apps, you will need to use a framework of some sort rather than writing your own framework from scratch.

Some reasons why you should NOT write your own framework:

  1. You're re-inventing the wheel, when it's been done many times over already.
  2. You're not very likely to do a better job than an open-source framework, which has been tested and iterated over by many developers.
  3. You'll spend all your time writing and debugging your own framework than you will spend on actually creating your application.

So yes, learn a couple of frameworks and find one that suits you the best!

LeeMobile
Good points. I'd also add that instead of rolling your own, it would be more productive to simply contribute to one of the myriad frameworks out there. Instead of 1000 developers each separately building their own framework, reinventing the wheel each time, it's far more preferable for them to get together and work together on a single framework.
Calvin
However, you will need to make your own if you're not satisfied with the current ones out there (like me). Oh, and it's fun :P
Bart van Heukelom
+2  A: 

Diclaimer: I'm NOT a php programmer and I have not EVER written a php application. On the other hand, I have installed, customized and used alot of php cmss for my site and shopping carts.

In my opinion php suffers from serious problems. The biggest one is that “framework” seems to be a foreign word for almost all big and even successful projects. Php code tends to become quickly spaghetti salad: spaghetti html mixed with spaghetti code and spaghetti sql.

osCommerce, one of the most successful shopping cart ever, is mostly unmaintable. That applies also the big majority of php projects.

Whether you should use a framework for you project, I say yes! Definitely! No matter how big is your project, using a web framework helps you tidying you code up and writing maintable code.

It also impact your programming style even when you are not using a framework.

Mouk
A: 

Using MVC-framework will make your development more easier. Especially database-related applications. It provides you a crystal clear folder structure and plenty of code libraries. I would suggest you start from CodeIgniter.

stanleyxu2005
A: 

Hello there, i just want to tell about my own experience in programming, I'm still newbie though

  1. first by using framework you'll get used to their coding style/rule, which is good because most of the framework are deeply thought about how they write their code. in short i get better style and cleaner code
  2. Usually framework come with many arsenal (plugins and or library), which you can find in internet, this will reduce your coding time, cut wasted time. In short you can make your own precious time thinking on business process
  3. with using open source framework, there's other programmer who already know and probably mastered the framework, then you can easily collaborate with others.
  4. in truth i'm not a well organized programmer, but it was before i 'm using some open source framework. perhaps like me you'll get more organized

That's all I can share with you for now, i'm not good with writing in english, sorry for that. but the point is i recommend you to use framework

Happy coding friend.

ibnu triyono
A: 

Frameworks are great when you got a team of developers working on the same project. The MVC controller integrates the designer + programmer beautifully. However, creating "framework-like" elements and "reinventing" the wheel isn't such a bad idea. If you're working on a huge project, it's better to get down and dirty with your code and customize EVERYTHING to fit your needs. It'll become a stronger product as it will be developed entirely for the project.

Greg Solak
You could customize good frameworks to fit your need. No need to customize EVERYTHING. like reinventing linux or use existing one that you could extend, like others have done in the past. Just dont reinvent things you dont have to reinvent.
never_had_a_name
A: 

The following post is in response to a thread that was immediately closed as I was writing my answer to RenderIn's post at: http://stackoverflow.com/questions/3265509/what-are-the-benefits-of-using-a-programming-framework . The thread was closed and in the comments a link was placed directing him to here, so I'll attempt to answer his question here. In quotes below is what I was ABOUT to submit:

"Allow me to recommend Joomla! to you and your organization. At my last employer, I had to pick-up PHP (having no prior experience with it), and after about a month and a half of doing some manual hand-coding of PHP, I was tasked to code a Joomla! component that would serve-up videos to users. I also had to create a backend that would allow non-techie administrators to categorize, edit, delete, etc., the videos as well as provide thumbnails for them, etc.

Now to get a working prototype for that, it took about two months (I was an intern at the time and only working 20-24 hours per week, so if you have quite a bit of PHP experience as well as experience with MVC development methodology, you probably could've gotten a working prototype up a LOT quicker than me)."

Now in response to the OP of THIS thread: Spending the time to learn a framework is definitely worthwhile (I haven't seen it mentioned in here until my post so I'll say it again: for a PHP-framework I'd recommend Joomla!).

Some of the benefits of learning a framework (an open-source one like Joomla!):

  • A huge community of people who can help answer your questions (besides stackoverflow; lol)
  • Access to ALL of the source code, so you can customize it however you want.
  • Lots of free (and paid) third-party plugins to enhance functionality.
  • Lots of tutorials.
  • Frameworks take care of performing a lot of mundane tasks automatically.

In reference to bullet four: Joomla! takes care of things for you such as database connection management and such so that you don't have to bother creating all your own custom functions to connect to your MySQL database or return different types of database results (e.g. one record, first result of first record, list of records, etc.), you simply place calls to theirs. Joomla!'s API is openly available on the web at their site: http://api.joomla.org/

Anyway hopefully this helps RenderIn and anyone else wondering about frameworks (especially PHP-related ones).

KSwift87
A: 

A framework to me is a good tool to speed you up and save your time for the sake of you just don't want to spend time to redo it, not because you want to save time that you don't know how much it is. You will pay for it if you do so.

To me framework is good if you are already a experience programmer and you have the touch or feel that you know how the framework roughly work below (just roughly not exactly) and have the confident to say ya if I want to I can re-create sort like simplify of this framework. Then a framework is a express car for you and it won't cause you the pain if you want to do something that the framework not ready for or something unusual or other odd thing.

If you don't, you better try to solve your problem using plain old PHP and go through the pain of playing the language at your finger, and learn about good programming practice and paradigm and pattern first. Else you will be one of those fresh graduate joining a large team and their first project is working on a project with a very powerful framework that require very less coding and more on configuring and patching. You will never be a good programmer and can't build a good PHP application from scratch.

How if you are in an organization that use a complex framework?

Spend some of your very own time to solve the problem in plain old in this case PHP until you get the touch of what I mentioned above. Else, you will never find your confident in programming and keep telling yourself, "I just know those are the steps are the way to do it". That is not programming (a bit extreme :)) .

Complex vs. Simple Framework

Some of the framework although used by many, is just to overwhelming. There is too many layers that you will lose track of. Those frameworks are usually for something which is stereotype, a lot of configuration files and if you want to do something unusual, you do better be the framework writer(a bit exaggerated here :)). I do not want to mention any name here, but you will know it when you encounter one.

ttchong