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.