Example of Laravel routing setting and sub-routing setting _php instance

Source: Internet
Author: User
Tags smarty template

This paper illustrates the Laravel Routing and Sub routing settings. Share to everyone for your reference, specific as follows:

Common 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 to filename (class name)
@index is the 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. Route:

Route::group ([' Namespace ' => ' Min '], function () {
  route::get (' Min/{index} ', ' Mincontroller@index ');
  Here the {index} is similar to regular, that is, the URL can be randomly lost: 127.0.0.1/min/$index is like a variable, you can lose anything. But the back of the @index 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 below the Min view folder
  }
}

Structure Chart:

More interested in laravel related content readers can view the site topics: "Laravel Framework Introduction and Advanced Course", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course ", PHP string (String) Usage summary," PHP+MYSQL Database operation Introduction Tutorial "and" PHP common database Operation Skills Summary "

I hope this article will help you with 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.