Laravel entry: MVC framework

Source: Internet
Author: User
Laravel entry: MVC framework
This article is based on Laravel 4.2. 1. route Hello World add the following code in app/routes. php and access http: // in the browser ://
 
  
/Helloworld can see the result. "Route: get ('/helloworld', function () {return'Hello world';}); "2. View can theoretically write all the code in app/routes. php, but this makes the code difficult to maintain. Therefore, we can move the specific page content to the view to make the routing file shorter. App/routes. php "Route: get ('/helloworld', function () {return View: make ('helloworld') ;}); app/views/helloworld. php  Hello world"3. Controller: we write a dynamic webpage with variables on the page. the variables are passed into the View through the Controller. App/routes. php (this time, our Route points to the Controller first, and then the Controller returns the View content) Route: get ('/helloworld', 'helloworldcontroller @ say '); app/controllers/HelloworldController. php"
    {$ Action }{{ $ name }}"The page displays" hello kitty "4. model as the business logic is complex, the Controller file will become longer and difficult to maintain, so we can divide the logic related to database query into the Model layer, you can even arrange a person who is good at designing database tables and writing SQL statements to take charge of this layer. App/routes. php "Route: get ('/helloworld', 'helloworldcontroller @ say'); app/controllers/HelloworldController. php
  Uid = $ uid; $ item-> name = $ name; $ item-> phone = $ phone; $ item-> save (); return $ item ;} // assume there are two rows of content: (1, 'Kitty ', '000000'), (2, 'dingdong', '000000') static public function getContacts {return DB :: table ('contacts')-> get () ;}} "app/views/hello/world. blade. php (because we need to use functions that go beyond the HTML syntax such as loops, we need to use the blade template language and add the blade part to the file name )"  @ Foreach ($ contacts as $ contact) {{$ contact-> name }}'s number is {{$ contact-> phone }}, @ endforeach"The page will show" kitty's number is 800888, dingdong's number is 900999, "for more syntax of the template language, refer to: https://laravel.com/docs/4.2/templatesto this, MVC (Model-View-Controller) the framework has evolved.
 

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.