设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

BC Morning V1806 门户 IT世界 资料备录 查看内容

Architecture of Laravel Applications

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

摘要: Laravel is referred to as a “full stack” framework because it handles everything from web serving to database management right down to HTML generation. A vertically integrated web development enviro ...
Convention Over Configuration

Laravel is referred to as a “full stack” framework because it handles everything from web serving to database management right down to HTML generation. A vertically integrated web development environment can provide a better experience for the developer.

The typical developer interacts with Laravel through a command-line utility that generates and manages the Laravel project environment. Laravel comes with an excellent command-line tool named Artisan that can be used to generate skeleton code and database schema stubs. Artisan handles everything from database schema migration to asset and configuration management.


Convention Over Configuration

One of the interesting features of Laravel is that it imposes some fairly serious constraints on how you structure your web applications. Surprisingly, these constraints make it easier to create applications - a lot easier. Let’s see why.

Laravel differs from other vertically integrated environments in its strong preference for convention over configuration. Whereas some Java, Python or PHP frameworks often require lots of XML configuration, Laravel requires almost none (or perhaps only a few lines of PHP) to get started. This aversion to configuration files makes for a very distinctive and recognizable code structure that is the same across all Laravel apps.


One Project Structure To Rule Them All!

It comes as no surprise that all Laravel projects have essentially the same directory structure - one in which every file has its designated place. By gently forcing this directory structure upon developers, Laravel ensures that your work is semi-automatically organized the “Laravel way”.

Figure 1.1 shows what the Laravel project directory structure looks like:

As you can see, this standard directory structure consists of quite a few subdirectories. This wealth of subdirectories can be overwhelming at first, but we’ll explore them one by one. Most of your work will happen in the app/ folder, but here’s a basic rundown on the function of each of the files and folders:

Top-level Folders Purpose
/app/ Contains the controllers, models, views and assets for your application. This is where the majority of the code for your application will live. You will be spending most of your time in this folder!
/public/ The only folder seen to the world as-is. This is the directory that you have to point your web server to. It contains the bootstrap file index.php which jump-starts the Laravel framework core. The public directory can also be used to hold any publicly accessible static assets such as CSS, Javascript files, images and other files.
/vendor/ A place for all third-party code. In a typical Laravel application, this includes the Laravel source code and its dependencies, and plugins containing additional prepackaged functionality.

As mentioned above, /app is where all the fun happens, so let’s have a deeper look at the structure of this directory.

Figure 1.2 shows the /app folder in detail:

File/Folder Purpose
/app/config/ Configure your application’s runtime rules, database, session and more. Contains a number of config files for changing various aspects of the framework. Most of the config files return associative PHP arrays of options.
/app/config/app.php Configuration for various application level settings, i.e. timezone, locale, debug mode and unique encryption key.
/app/config/auth.php Configuration that controls how user authentication will be performed in the application, i.e. authentication driver
/app/config/cache.php If the application utilizes caching to speed up response time, this is where you configure the feature.
/app/config/database.php Contains relevant configuration information for the database, i.e. default database engine and connection information.
/app/config/mail.php Configuration for e-mail sender engine, i.e. SMTP server, From: header
/app/config/session.php Configuration that controls how user sessions are managed by Laravel, i.e. session driver, session lifetime.
/app/config/view.php Misc. configuration settings for templating systems.
/app/controllers Contains the controller classes that are used to provide basic logic, interact with data models, and load view files for your application.
/app/database/migrations/ The migrations folder contains PHP classes which allow Laravel to update the Schema of your current database while keeping all versions of the database in sync. Migration files are generated using the Artisan tool.
/app/database/seeds/ The seeds folder contains PHP files which allow Artisan to populate database tables with reference data.
/app/lang/ PHP files containing arrays of strings to enable easy localization of the application. By default the directory contains language lines for pagination and form validation for the English language.
/app/models/ Models are classes that represent the information (data) of the application and the rules to manipulate that data. In most cases, each table in your database will correspond to one model in your application. The bulk of your application’s business logic will be concentrated in the models.
/app/start/ Contains custom settings related to the artisan tool as well as global and local context.
/app/storage/ The storage directory is used as temporary file store for various Laravel services such as sessions, cache, compiled view templates. This directory must be writable by the web server. This directory is maintained by Laravel and you need not tinker with it.
/app/tests/ The tests folder provides a convenient location for you to keep your application Unit tests. If you are using PHPUnit, you can execute all tests at once using the Laravel Artisan tool.
/app/views/ The views directory contains your HTML template files used by controllers or routes. Note that you should place only the view template files in this location. Other static assests such as stylesheet, javascript and image files should be placed in the /public folder instead.
/app/routes.php This is your application’s routing file which holds routing rules that tells Laravel how to connect incoming requests to route handler closure functions, controllers and actions. This file also contains declarations for several events including error pages, and can be used to define view composers.
/app/filters.php This file contains various application & route filter methods that alter the outcome of your application. Laravel has some pre-defined filters for access control and XSS protection.

A lot of thought has gone into establishing and naming the folders, and the result is an application with a well structured file system.

Here is what you get:


123下一页

路过

雷人

握手

鲜花

鸡蛋

相关阅读

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

GMT-8, 2025-7-8 10:24 , Processed in 0.013654 second(s), 19 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

返回顶部