MVC design of laravel framework

Source: Internet
Author: User
Laravel framework-MVC design more articles visit the technical blog: goofyy technology House

Technical Blog website: http://www.goofyy.com

A few days ago, I wrote a brief description of the MVC framework. I will give you a general introduction. this small series will be combined with the Laravel framework for detailed demonstration.

Development Environment: Laravel version: 5.0.22php version: 5.5.11mysql version: 5.6.16

Through the previous articles, we clearly know that the MVC framework. M is data storage, V is view display, C is responsible for data processing, connect V and M. After configuring the Laracel environment, let's take a look. The system provides us with a page

php artisan serve

Start the server and access http: // localhost: 8000 to see the laravel welcome page.

Next let's take a look at the routing file/app/Http/routes. php

Route::get('/', 'WelcomeController@index');Route::get('home', 'HomeController@index');Route::controllers(['auth' => 'Auth\AuthController','password' => 'Auth\PasswordController',]);

By viewing the route, we can see that when we access localhost: 8000, the index of WelcomeController is accessed by default. Here, WelcomeController is the so-called Controller. Then we find the file. /App/Http/Controller/WelcomeController. php.

public function index(){return view('welcome');}

Obviously, a view is returned, and its name is welcome. Then we can find welcome in the view. The Directory of the view is/resourse/views/welcome. blade. php. Here, blade is a view template. Then the http: // localhost: 8000 we accessed is actually the view. Draw a picture to show your thoughts. M is not used here (database operations)

We should probably understand it here. let's write one here.

Add a route,/app/Http/routes. php

Route::get('goofyy','GoofyyController@index');

Then add the GooyyController file to the Controller. There are two ways to create a file: manual creation, terminal creation, and terminal creation.

php artisan make:controller GoofyyController

The difference is that the created terminal contains some default methods.

After the index is created, create the index method. if the index is created on a terminal and already included, change it,

public function index()    {     return view('GoofyyView')  ;    }

Create the GoofyyView. blade. php file in the view. if you do not write too much, write a sentence.

Goofyy technology House

Then we visit the webpage, http: // localhost: 8000/goofyy

Then the page is displayed, indicating that success will be applied to the first small experiment. In the GoofyyView. blade. php template of view, you can use html, js, and so on. The blade template is the function of Laravel zookeeper.

Next we will write a program with M (data operations.

Or use the newly created file,

Change the GoofyyController. php index method in the Controller.

    public function index() {    $array1 = [      'name' => "Goofyy",        'age' => "22",    ];    return view('GoofyyController',$array1);   //return view('GoofyyController')->with('name'=>'Goofyy')->with('age'=>'22');   }

There are two methods for passing parameters: array and. The array is relatively clear, and it is messy and troublesome to pass with multiple values.

Then we use it in the View. GoofyyView. blade. php changes as follows:

Goofyy technology House my name: {$ name} age {$ age} accidentally exposed age

The style is also used in the blade template. The next article describes the strength of the blader template.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.