Jump to content
MakeWebGames

Why You Should Use a PHP Framework


Karlos94

Recommended Posts

What is a PHP Framework?

PHP is the world’s most popular scripting language for many different reasons – flexibility, ease-of-use, among others – but often times coding in PHP, or any language for that matter, can get rather monotonous and repetitive. That’s where a PHP framework can help.

PHP frameworks streamline the the development of web applications written in PHP by providing a basic structure for which to build the web applications. In other words, PHP frameworks help to promote rapid application development (RAD), which saves you time, helps build more stable applications, and reduces the amount of repetitive coding for developers. Frameworks can also help beginners to build more stable apps by ensuring proper database interaction and coding on the presentation layer. This allows you to spend more time creating the actual web application, instead of spending time writing repetitive code.

The general idea behind the workings of a PHP framework is referred to as Model View Controller (MVC). MVC is an architectural pattern in programming that isolates business logic from the UI, allowing one to be modified separately from the other (also known as separation of concerns). With MVC, Model refers to data, View refers to the presentation layer, and Controller to the application or business logic. Basically, MVC breaks up the development process of an application, so you can work on individual elements while others are unaffected. Essentially, this makes coding in PHP faster and less complicated.

 

Why Should we use a PHP Framework?

Developers should utilize PHP frameworks for various reasons, but the number one reason is for speeding up the development process. Reusing code across similar projects will save the developer a substantial amount of time and effort. A framework offers pre-built modules for performing tedious coding tasks, so the developer can spend their time on developing the actual application rather than re-building the foundation with each and every project.

Stability is another big reason developers are utilizing frameworks. While simplicity is one of PHP’s greatest assets, and the reason many people prefer to use this scripting language, it can also be one of its biggest downfalls. It’s fairly easy, especially for beginners, to write bad code and not even realize it. With PHP the application will often times still work, but unknowingly you may have opened up a large security hole in your coding that may be susceptible to attacks. It’s important to remember that PHP is a very forgiving language, so it’s even more important to make sure to tie up any loose ends in your coding – even if the application seems to be working properly.

Finally, the availability of PHP frameworks is extensive, and there are many different frameworks to choose from. You can even create your own, although many developers elect to choose from any of the most well-known frameworks due to their popularity, large support teams, and their forums/communities that allow you to interact with other developers who utilize the same framework. As a side note, you should always examine your project to first decide if you should even use a framework or not. Some questions you should ask yourself are: Will it save you, and anyone else who may use it, time and effort? Will the app perform better? Will it improve stability? If you can answer yes to any of these questions, a PHP framework may be the right answer for that particular project.

 

When to use a PHP Framework?

This is a common question amongst experienced and beginner developers alike, and there’s really no direct answer to the question. For many beginners, a framework will offer greater simplicity as well stability, so it may be a good idea to use PHP frameworks whenever possible. It will help reduce or eliminate bad coding and speed up the build process.

On the other hand, many experienced PHP programmers see frameworks as tools for “weak” programmers that don’t understand how to write good, clean code. Whether this is true or not is up for debate, but the fact of the matter is that PHP frameworks are a tool that can be used to save time and tighten up one’s coding.

When working on a project with tight deadlines, utilizing a PHP framework is a huge benefit that can greatly speed up the coding process. So if you’re in a time crunch, PHP frameworks can be very beneficial to you. Another instance when PHP frameworks should be a consideration is when you’re working on projects with substantial amounts of monotonous coding, because it will help make the job much less tedious.

 

What to Look for in a PHP Framework?

There’s plenty of options available to anyone who may be searching for PHP frameworks, and there’s even the option of creating your own, although that’s only recommended for PHP experts. When searching for the the PHP framework best suited for your needs, it’s important to keep in mind who will be using and/or modifying your applications from top to bottom. If there are many people who will be using the application, it may be best use a popular PHP framework that many developers are familiar with. On the other hand, if you wish to build web applications for your own personal use, you are better off choosing any PHP framework that you’re comfortable with – whether it’s popular amongst the developer community or not.

Various factors to search for in a PHP framework include: easy of use, rapid development/performance, popularity amongst other developers, strong features, and support/forums. It’s recommended to try out several PHP frameworks when you’re first starting out in order to find one that suits your needs the best. All frameworks are slightly different and have varying strengths and weaknesses, for instance Zend Framework has been around since V3 and is full of features plus has an extensive support system in place since it has been around for so long. On the contrary, CakePHP is another PHP framework which is younger than Zend Framework and has slightly less of a support system in place (although support for this framework is growing rapidly), but is much more user-friendly and easy to use.

As you can see, each type of PHP framework has its own advantages, so it’s best to use a bit of trial and error to figure out which one will work the best for your needs. Another excellent way of choosing a framework is to consult your colleagues in the development community to see which ones they prefer. Those who have actually used a specific framework will be able to inform you of the ease-of-use, features, support availability, scope of the community surrounding the framework, and possible shortfalls.

 

Most Common Mistakes When Using a PHP Framework

Mistakes are possible in any type of programming, but PHP frameworks help to limit these mistakes greatly by providing good quality code that is tried and true from the start of the development process. Repetitive coding seems to promote mistakes now and then, and frameworks all but eliminate that problem.

That being said, there are still things to be careful of when utilizing any PHP framework. For instance, unless you are an expert in PHP programming, you should always opt for using a popular framework with plenty of support and an active user base (see below for examples of popular PHP frameworks). There are many frameworks out there that have little or no support, and/or they were created by individuals with limited knowledge of PHP. These types of frameworks can cause your applications to not function properly, and worse case scenario, could cause catastrophic security issues with your website.

Another somewhat common mistake is not ensuring your database and web server is compatible with the particular framework. For example, Seagull PHP Framework recommends the following configuration:

  • PHP: PHP 4.3.0 is the minimum, later versions work fine, as do versions PHP 5.1.1 and above. Avoid anything in the 5.0.x series
  • MySQL: MySQL 4.0.x, 4.1.x and 5.0.x are all supported. You can also use 3.23.x.
  • Apache: Seagull works fine with 1.3.x and 2.x series of Apache

If you don’t meet these requirements, you won’t be observing the best performance possible from your chosen framework. Even if you are an expert in PHP, you should always go over the documentation of the framework to confirm compatibility before trying it out.

Similar to the previously mentioned common mistake, not following the recommended installation process of your PHP framework can also give you some headaches. Take Seagull as an example again – the Seagull wiki has a detailed rundown of the framework’s installation process that has several key steps that are sometimes easily overlooked by careless or unsuspecting developers. The key is to take your time setting up the framework and follow the installation instructions to the “T” – The time you’ll save actually developing applications later will more than make up for the few extra minutes spent installing the framework correctly the first time.

 

Summary

PHP frameworks are a great way for developers of all skill levels to reduce the need for repetitive coding, speed up the development process, and to ensure proper coding when creating web applications. This not only speeds up the development of rich applications, but it also tightens up PHP security by reducing the risk of security holes in your coding.

While some expert PHP coders do not feel the need to use frameworks to develop web apps, they can still be an advantage in situations where rapid development is necessary, such as under tight deadlines. And for beginner to intermediate developers, frameworks can enhance the PHP learning process while promoting good coding practices and reducing bad coding, which is common in PHP due to its “forgiving” nature.

There are many PHP frameworks available today, and thus developers are sure to find a framework that fits there needs in terms of features, support, speed, scalability and more. Some of the top PHP frameworks used by developers today include: The Zend Framework, CakePHP, Symfony, Codelgniter, and Seagull.

From: http://www.noupe.com/php/discussing-php-frameworks.html

Here are a few links to the more popular PHP frameworks.

 

Using a PHP framework is just something I'd recommend, I personally use CodeIgniter as it does what I need, it's simple to use and it is a lightweight framework.

Link to comment
Share on other sites

Quiet a good post, however you don't say what those frameworks can do for you and what are the downsides (as there is some).

Keep in mind that frameworks varies a lot from framework to framework, and learning / mastering one can be time consuming. So choose wisely which one you want to use.

Finally study what kind of license those frameworks are based on as some could force your code to be an open source as well, which may not be your wish.

Link to comment
Share on other sites

I used CodeIgniter, but then my friend showed me the Yii.

CodeIgniter (developed from CakePHP) has lower mastering curve than Yii.

I would recomend codeigniter for intermediate php devlopers and Yii for advanced developers for large scale projects.

What I like about Yii, is that you can usee third party extensions/libaries. For example you can, use Zend Framework components as "vendors" and create your own extensions what can be reused with Yii.

Link to comment
Share on other sites

I used CodeIgniter, but then my friend showed me the Yii.

CodeIgniter (developed from CakePHP) has lower mastering curve than Yii.

I would recomend codeigniter for intermediate php devlopers and Yii for advanced developers for large scale projects.

What I like about Yii, is that you can usee third party extensions/libaries. For example you can, use Zend Framework components as "vendors" and create your own extensions what can be reused with Yii.

I hate frameworks that force me to use the command line.. I'd try it of it didn't..

Link to comment
Share on other sites

Do you mean Yii? You don't have to use commandline. You can create structure on your own, mannually. Commandline just helps to generate structure.

Using framework depends on how big is your project. For little website you don't need fancy framework. But when you are developing large scale projects then it is easier to manage it. Frameworks are ment to make our live easier, but if you use wrong framework at wrong time then you just make your life harder.

For example I downloaded mmc lite opened zip file, there was 50+ .php files looking at me, no structure at all. I closed the file and deleted it.

Link to comment
Share on other sites

Well

Do you mean Yii? You don't have to use commandline. You can create structure on your own, mannually. Commandline just helps to generate structure.

Using framework depends on how big is your project. For little website you don't need fancy framework. But when you are developing large scale projects then it is easier to manage it. Frameworks are ment to make our live easier, but if you use wrong framework at wrong time then you just make your life harder.

For example I downloaded mmc lite opened zip file, there was 50+ .php files looking at me, no structure at all. I closed the file and deleted it.

Well from my experience yesterday, going through the screencasts.. I saw the command line way of creating a 'skeleton web app' but no other way? Care to explain how I can do it without the cmd?

Link to comment
Share on other sites

I've recently got into CodeIgniter and I have to say it's one of the best things I've done in my developing career.

I don't think I will move from CodeIgniter to a framework, as it provides me with everything I need to build a powerful system.

The disadvantages of CodeIgniter is that it's not that advanced yet and takes quite a while to learn, but Yii, Zend and CakePHP takes ages to learn. You could say CodeIgniter is to Yii what jQuery is to MooTools. It's simple and allows you to write beautiful code, but it can only go so far.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...