Laravel Route setting and sub-route setting example Analysis _php instance

Source: Internet
Author: User
Tags smarty template
This paper describes the Laravel routing and sub-route setting methods. Share to everyone for your reference, as follows:

Normal routing settings

1. Routing (routes.php) code:

Route::get (' min ', ' mincontroller@index ');

Min: For the route name, which is entered in the URL, such as 127.0.0.1/min here min is the corresponding min
Mincontroller as file name (class name)
@index as Method name

2. Controller

Namespace App\http\controllers;use app\http\controllers\controller;class Mincontroller extends controller{  Public Function Index () {     $name = ' Specs1 ';    Return view (' index ')->with (' name ', $name);}  }

Sub-route

1. Routing:

Route::group ([' namespace ' = ' Min '], function () {  route::get (' Min/{index} ', ' Mincontroller@index ');  Here the {index} is similar to the regular, that is, the URL can be randomly lost: 127.0.0.1/min/$index like a variable, you can lose anything. But the @index in the back is the Real method});

Controller:

Namespace App\http\controllers\min;//min is the controller's folder path use App\http\controllers\controller;class Mincontroller extends controller{Public  Function Index () {     $name = ' Specs1 ';    Return view (' Min.index ')->with (' name ', $name);//The min.index here is equivalent to Min/index  is the index.blade.php file under the Min view folder  }}

Structure diagram:

More interested in laravel related content readers can view this site topic: "Laravel Framework Introductory and Advanced tutorial", "PHP Excellent Development Framework Summary", "Smarty Template Primer Basic Tutorial", "PHP date and Time usage summary", "PHP object-oriented Programming introduction tutorial "," PHP String Usage Summary "," Introduction to Php+mysql Database Operations "and" PHP common database Operation Skills Summary "

It is hoped that this article is helpful to the PHP program design based on Laravel framework.

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