找回密码
 注册

QQ登录

只需一步,快速开始

BCM 门户 IT世界 资料备录 查看内容

Introduction to Laravel Framework

2014-1-13 15:12| 发布者: Test| 查看: 800| 评论: 0|来自: laravel book

摘要: This book is about Laravel, a web application development framework that saves you time and effort and makes web development a joy. Laravel has shaken up the PHP community in a big way - especially wh ...
Primary of Laravel: separation of concerns


Again, don’t worry too much about the details; just get a feel for the overall design of the app. The primary thing to note in the Laravel-powered application is the separation of concerns:

  • Our database table is now represented by a PHP class. This class is called a “model”. Using it, you can create, retrieve, update and delete records (“CRUD”) in your database using simple PHP methods rather than writing tedious SQL statements.

  • The EntriesController controller specifies which response is returned for a given URL pattern. In our case, the HTTP GET / request will be handled by the getIndex() method, and HTTP POST / request will be handled by the postIndex() controller. Our application logic is contained within these two controllers.

  • The app/views/home.blade.php file is an HTML view template that describes the design of the page. It uses the Laravel Blade template language with basic logic statements - e.g., @foreach($entries as $entry)

Taken together, these pieces loosely follow a design pattern called Model-View-Controller (MVC). Simply put, MVC is way of developing software so that the code for defining and accessing data (the model) is separate from request-routing logic (the controller), which in turn is separate from the user interface (the view). (We shall discuss MVC in more depth in a later chapter.)

A key advantage of such an approach is that components are loosely coupled. Each distinct piece of a Laravel web application has a single key purpose and can be changed independently without affecting the other pieces. For instance:

  • a developer can change the URL for a given part of the application without affecting the underlying implementation.
  • a designer can change a page’s HTML without having to touch the PHP code that renders it.
  • a database administrator can rename a database table and specify the change in a single location, rather than having to search and replace through dozens of files.

If all this code were interspersed through a single HTML-PHP hybrid file that contained the HTML view as well as all the model and controller (routing) data, it would not be nearly as manageable and maintainable. Design patterns such as MVC are created to make a developer’s life easier. This is where web frameworks like Laravel score over plain PHP.

The Laravel Advantage

Laravel embraces a general development philosophy that sets a high priority on creating maintainable code. By following some simple guidelines, you should be able to keep a rapid pace of development and be free to change your code with little fear of breaking existing functionality. Laravel achieves this by adopting several proven web development patterns and best practices.

Single Responsibility Pattern

The Laravel MVC architecture is great from a developer’s perspective because it separates each component of a web application into an isolated code base that is easily managed without having to worry about breaking other parts of your application.

Convention over configuration

Laravel defines the directory structure of your application for you and sets a series of conventions for naming files, classes, and database tables. It takes advantage of these conventions to tie together your application without a lot of configuration. You may initially be concerned about the idea of Laravel telling you how to structure your application. Worry not! You’ll quickly notice that not having to make these judgements yourself actually speeds up development time and creates a more consistent code base between different teams members and projects. By choosing smart defaults, Laravel allows you to focus on the functionality of your application and develop powerful web applications quickly, with code that is clean and easy to maintain.

Don’t-Repeat-Yourself (DRY)

Laravel promotes the DRY principle. Functionality is written cleanly once, and only once. Laravel provides an environment that makes it easy to consolidate shared code between different components of your application.

Unit testing

Laravel gives much importance to testing. Writing code is always done in parallel with tests to ensure the code works as intended and will continue to work when things around it change.

1234

鲜花

握手

雷人

路过

鸡蛋

相关阅读

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )

GMT-8, 2026-4-12 05:02 , Processed in 0.014323 second(s), 18 queries .

Supported by Weloment Group X3.5

© 2008-2026 Best Deal Online

返回顶部