MVC Design of Laravel frame

Source: Internet
Author: User
Tags php template
More articles visit the Tech blog: goofyy Technology

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

A few days ago to write a brief introduction to the MVC framework, roughly speaking, this small series combined with the Laravel framework to give you a concrete demonstration.

Development of the Bad Environment: Laravel version: 5.0.22php version:    5.5.11mysql version: 5.6.16

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

PHP Artisan Serve

Start the server, visit http://localhost:8000 to see Laravel's Welcome page

Then 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 looking at the route, we can see that when we visit localhost:8000, the default access is Welcomecontroller index. The Welcomecontroller here is the so-called controller. Then we find the file. /app/http/controller/welcomecontroller.php.

Public Function Index () {return view (' Welcome ');}

Clearly see return a view, name is welcome. Then we'll find welcome in the view. The catalog for the view is/resourse/views/welcome.blade.php. Here blade is a view template. And then the http://localhost:8000 we're visiting is actually the view. Draw a diagram to show the idea, there is no use of M (database operation)

See here probably should understand, below let us write one.

Add a route first,/app/http/routes.php

Route::get (' Goofyy ', ' goofyycontroller@index ');

Then we add the Gooyycontroller file in the controller, there are two ways to create a file, one is manually created, one is terminal creation, the terminal creation method is

PHP Artisan Make:controller Goofyycontroller

The difference is that terminal creation contains some default methods.

After creation is complete. Create the index method, if it is a terminal created, already contained, modified to,

Public Function Index ()    {     return view (' Goofyyview ')  ;    }

Then create the GoofyyView.blade.php file in the view, write a sentence without writing too much.

Goofyy Technology Residence

Then we visit in the Web, Http://localhost:8000/goofyy

Then the interface you get shows that the first little experiment you success. In the view GoofyyView.blade.php template, you can use HTML,JS and so on, blade template is the function of Laravel pillbox pillbox.

A program with m (data manipulation) is written below.

Or with a newly created file,

Change the index method of the goofyycontroller.php inside the controller.

    Public Function Index () {    $array 1 = [      ' name ' = + ' goofyy ', ' age ' = ', '    ];    Return view (' Goofyycontroller ', $array 1);   Return view (' Goofyycontroller ')->with (' name ' = ' Goofyy ')->with (' age ' = ');   }

There are two ways to pass a parameter, array and with. The array is relatively clear, and with a number of values in the time, it seems very messy and troublesome.

Then we use it inside the view. GoofyyView.blade.php changes as follows

Goofyy Technical Residence My name: {{$name}} age {{$age}}

I accidentally exposed my age.

In the blade template is also used style, pillbox pillbox bar. Next article talk about the power of the Blader template

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

  • 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.