Home >Backend Development >PHP Tutorial >Laravel routing setting and sub-routing setting example analysis, laravel example analysis_PHP tutorial

Laravel routing setting and sub-routing setting example analysis, laravel example analysis_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:55:14861browse

Laravel routing setting and sub-routing setting example analysis, laravel example analysis

This article describes the Laravel routing setting and sub-routing setting method with examples. Share it with everyone for your reference, the details are as follows:

Normal routing settings

1. Routing (routes.php) code:

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

min: is the route name, which is entered in the URL, such as 127.0.0.1/min The min here is the corresponding min
above MinController is the file name (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);
  }
}

Subroute

1. Routing:

Route::group(['namespace' => 'Min'], function () {
  Route::get('min/{index}','MinController@index');
  //这里的{index}类似于正则,即url可以随意输:127.0.0.1/min/$index 就像变量一样,输什么都可以。但是后面的@index是真正的方法
});

Controller:

namespace App\Http\Controllers\Min;//Min是控制器的文件夹路径
use App\Http\Controllers\Controller;
class MinController extends Controller{
  public function index(){
     $name = 'Specs1';
    return view('min.index')->with('name',$name);//这里的min.index等价于min/index  是min视图文件夹下面的index.blade.php文件
  }
}

Structure diagram:

Readers who are interested in more information about Laravel can check out the special topics on this site: "Introduction and Advanced Tutorial on Laravel Framework", "Summary of PHP Excellent Development Framework", "Basic Tutorial on Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the Laravel framework.

Articles you may be interested in:

  • Introduction to Laravel 5 framework learning routes, controllers and views
  • ThinkPHP, ZF2, Yaf, Laravel framework routing competition
  • Laravel 4 Basic Tutorial: Views, Namespaces, and Routing
  • Learn the road to Laravel with me
  • Laravel framework routing configuration summary and setup tips
  • Laravel5. 1 Methods of connecting to the database, creating a database, creating a model and creating a controller
  • Detailed explanation of usage examples of Trait in Laravel
  • Laravel's method of implementing automatic dependency injection of constructors
  • Based on laravel production APP interface (API)
  • PHP framework Laravel learning experience
  • Get the previous and next article data in Laravel

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117066.htmlTechArticleLaravel routing settings and sub-routing setting example analysis, laravel example analysis This article describes Laravel routing settings and sub-routing examples. Setting method. Share it with everyone for your reference, the details are as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn