Difference between revisions of "Web Frameworks"
(Created page with 'So far in this class, you have been using PHP to run your web site. You may have found that PHP can become burdensome when you are writing complex applications, and it can be ha…')
Revision as of 01:55, 25 August 2012
So far in this class, you have been using PHP to run your web site. You may have found that PHP can become burdensome when you are writing complex applications, and it can be hard to use for collaboration.
Web Frameworks are an alternative method for writing web applications. Web Frameworks are designed to make the experience for the developer more elegant and increase the possibilities for collaboration.
There are hundreds of Web Frameworks out there. We have chosen three of the more popular frameworks to write about in this article. If you want to use a different framework, there is a section at the end telling you what to look out for.
Common Features of Web Frameworks
Many Web Frameworks use an object-relational mapping paradigm for communication with the database. What this means is that instead of writing SQL queries, you call methods on objects instead. For example, the following snippet of code in Ruby on Rails loads a certain user out of the database and changes their nickname:
u = User.find_by_username("alice") u.update_attributes( nickname: "Ali" )
In PHP, your code probably ended up jumbled together in various disorganized places. This is part of the reason why many Web Frameworks choose to use a Model-View-Controller architecture.
A directory structure for an MVC framework might look like the following:
- app (holds MVC components)
- models (contains models)
- controllers (contains controllers)
- views (contains views)
- config (holds global server configurations)
- lib (other assorted libraries)
With an MVC architecture, a request to the server typically follows the following path:
- The server routes the request to a certain controller.
- The controller interprets the request, loading requested information from the models.
- The controller passes the information from the models to a view.
- The final view is sent to the user.
Some Popular Web Frameworks
Ruby on Rails
Ruby on Rails, or just Rails, is an open source web development framework that uses Ruby as its programming language. Ruby is similar in syntax to Python, and it was chosen for Rails because of its elegant syntax and adaptability.
Rails uses ActiveRecord, an object-relational mapping library, to communicate with its database back-end. Rails also employs an MVC architecture.
Rails is great for web sites that follow a typical web design pattern: for example, blogs, e-commerce, and news sites.
Ruby on Rails Resources
Notable Sites using Ruby on Rails
Other Web Frameworks
Bayong Rails, Django, and CakePHP, there are hundreds, if not thousands, of web frameworks. Here are some things to keep in mind when choosing a framework: