开发者

When are frameworks used in PHP or any other language?

When do we have the necessity of using the frameworks in PHP. I have heard about zend framework and symfony. I have read about them but still didn't understand that exact point开发者_JS百科 why we use the frameworks in software development.


Frameworks often provide you the boiler plate code that you would have to otherwise use, such as: Session Management, Templating, Database access etc etc.

In terms of proper software engineering, using these frameworks tend to promote proper design with patterns such as MVC(Model, View, Controller). By using this pattern, you can increase code reusability, separation of concern, etc.

By utilizing the database access that these frameworks provide you, you can write efficient models that can interact with the database while promoting code reusability. Another thing to consider with databases is security, such as SQL injections. Most frameworks now-a-days will automatically protect you against these type of attacks. If you were to write your own code(without a framework), you could end up leaving some sort of query wide open for sql injections.

For controllers, these frameworks tend to provide some sort of URL mapping. An example might be domain.com/posts/edit/5. The framework will then parse this url, and call the controller "posts", method "edit", and pass in the id 5. As you can see, if you weren't using a framework, you'd have to write all this code yourself, which would increase the amount of time coding and more chance of mistakes.

For the views, often times templating systems are in place to help reduce the amount of html, css, javascript etc you write. Not only that, they also provide structure for your views. In other words, they help you put your views in directories/locations that make logical sense(in terms of reusability, ease of use, etc).

Summary:

Because of all these features, you can see that not only will this reduce the amount of error/bugs in your system, but also decrease the amount of developing time.

Of course there are downsides to everything, and this is no exception. The main problem is the learning curve of learning these new frameworks. Often times frameworks provide so much that you have to learn all these new features just to get up and running.

Some popular PHP frameworks:

CodeIgniter

CakePHP

Zend Framework

Symfony

Getting Started Guides:

CodeIgniter

CakePHP

Zend Framework

Symfony

In terms of never using a framework before and wanting to get started, I'd highly suggest CodeIgniter. The learning curve is no where near as high as the other ones, however provide enough boiler-plate code and features that it should get you up and running.

If you want to do your own research(which you should!), here is a comparision table of all popular PHP frameworks:

http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2


Frameworks are usually used to accelerate the development of a project. Imagine having a bunch of extra new functions to help you with things like logins, page generation, database management, etc.. on top of the basic php functions. Basically Frameworks are made to save time and stop reinventing the wheel every time you make a new site/etc...


I have used CodeIgniter to build a few website and web applications.

The main advantage is that you get many pre-built components such as database abstraction, sessions management, email sending tools, and so on in one consistent interface and one package, so you don't have to spend time looking for these components that may or may not work well together.

Each framework has a different feel to it, a learning curve, limitations, you need to try them out and get a feel for it.

Many years ago, I was using Macromedia's Dreamweaver with a 3rd party extension to build my web applications. Since that time, Dreamweaver is owned by Adobe and the 3rd party extension is off the market, so I have legacy code with no support. For me, being messed around my market forces gave me the incentive to seek out a framework that was "desktop independent".

Summary: As a web developer, the primary benefits of a framework are ease of use, reusable components and greater control over rate of obsolescence.


Another point not made (i think) is that regardless of framework, but assuming it is well made, mature and has a community is that it has a structure that is imposed on the developers, whether it be MVC or REST, that future developers can quickly get to grips with when extending or maintaining the codebase.

So the naming convention for classes and objects & structures, the structure of the files and directories , the location of third party code, the templating system, localisation/internationalisation etc. in a well designed (and mature) framework will be well defined and accessible through third party or community maintained documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜