Bộ định tuyến php psr

Khi người dùng truy cập trang web bằng cách nhập URL vào trình duyệt. Ứng dụng HTTP Request nhận được sẽ phân tích URL này và dẫn đến một hành động trong bộ điều khiển. Việc phân tích URL như dẫn đến cuộc gọi hành động tương ứng như vậy là quá trình định tuyến [tuyển định]. Trong ZF chắc chắn công việc này là thư viện

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
5

Phần này chỉ nói về Routing cơ bản ứng dụng trong Skeleton của ZF, còn chi tiết nâng cao sau này hãy đọc Router trong ZF

Cấu trúc URL

Một URL nhận được từ Yêu cầu HTTP có một số thành phần. ________ 56, ________ 57, ________ 00, ________ 01, ________ 02

Ví dụ

http. //Địa điểm. tên miền của bạn. com/path/to/page/#section?a=1&b=price

Do đó URL bắt đầu bởi lược đồ với các giá trị như http. //, https. //. Theo sau là tên máy chủ như www. tên miền của bạn. com, google. com. Có thể có đường dẫn đến trang theo cấu trúc thư mục cấu trúc, cách thành phần cách nhau bởi

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
3 as product/category/cate1. Nếu có đoạn thì nó bắt đầu bởi ký tự
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
4, nó biểu thị diễn điểm bắt đầu của một nội dung nào đó trong trang [mặc định trình duyệt sẽ cuộn trang tới đoạn]. Truy vấn chuỗi nếu nó bắt đầu với
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
5 tiếp theo là các cặp
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
6 cách nhau bởi
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
7

Các ký tự đặc biệt trong các thành phần đường dẫn, đoạn, truy vấn của URL phải được mã hóa, ví dụ

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
8 trên URL sẽ là
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
9. Trong PHP có hàm
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
00 giúp bạn mã hóa. Đồng thời có
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
01 giúp bạn giải mã chuỗi URL

Các loại Route trong ZF

Một lộ trình khi nhận được URL thông tin từ Yêu cầu HTTP sẽ phân tích nó và trả lời rằng URL có phù hợp với nó hay không. Khi ứng dụng nhận thấy URL phù hợp với Route nào, thì dựa theo cấu hình mà tiến trình khởi động Controller phù hợp cũng như gọi hành động

theo cách mà Route phân tích, ZF chia ra mấy loại sau

RouteChi tiếtLiteralCác phần của URL chính xác với các phần của RouteSegmentSo sánh các đoạn đường dẫn của URLRegexSó so sánh đường dẫn URL với một biểu thức chính quy mẫuHostnameKiểm tra sự phù hợp của máy chủ lưu trữ với một số mẫu so sánhSchemeKiểm tra lược đồ phù hợp với sự phù hợp

Skeleton ZF ứng dụng Route như thế nào?

Các loại Route ở trên, được sử dụng để tạo các route trong ứng dụng. Skeleton sẽ tập hợp các route mà bạn cấu hình lại trong một đối tượng

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
02

Khi cho

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
03 phân tích Yêu cầu HTTP gửi đến [->match[$request]], nó sẽ trả về một đối tượng
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
04 [Zend\Router\Http\RouteMatch] nếu có Tuyến phù hợp hoặc nếu Yêu cầu HTTP rỗng không phù hợp với

With Skeleton in the active process of it, has giai đoạn it will get

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
04, the base information in
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
04 that Skeleton know will with the start up Controller nào. Vì
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
08 chứa các tham số được mô tả bởi Route, nên lấy tham số này bằng $RouteMath->getParam['paramname']

Nếu có nhu cầu lấy

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
04 trong ứng dụng thì có thể làm như sau

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
0

Trong ứng dụng Skeleton, các Route được khai báo, cấu hình. ở trong tệp

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
10, ở mục
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
11 của phần tử
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
12

You can open file. mô-đun/Ứng dụng/cấu hình/mô-đun. cấu hình. kiểm tra php

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],

Như bạn thấy hai route khai báo có tên là

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
13 và
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
14

Sử dụng Route - Literal

Đây là loại Route so sánh tên chính xác tuyệt đối, cụ thể

Cú pháp khai báo để có được tuyến đường này trong mô-đun. cấu hình. php as after

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
0
  • nameroute tên tuyến đường do bạn tự đặt, chọn một cái tên không trùng với tên tuyến đường khác như 'home', 'about', 'contact'
  • nghĩa đen. class for known here is route type Literal, memory has loading [use Zend\Router\Http\Literal]
  • NameController tên bộ điều khiển mà route này biểu diễn, tên này là tên bộ điều khiển đã được đăng ký trong hệ thống [] as.
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    15,
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    16
  • nameaction tên của hành động trong bộ điều khiển phù hợp với Route này, ví dụ
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    17,
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    18

Ví dụ. Khai báo route có tên

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
19 để khi nhập địa chỉ là
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
30 thì sẽ gọi hành động có tên
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
18 của bộ điều khiển có tên đăng ký
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
32

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
1

Use Route - Segment

Route này so sánh sự tương ứng của các thành phần trong đường dẫn URL với mô tả của Route

Cú pháp khai báo cấu hình

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
3

in which

nameaction tên hành động mặc định phù hợp và sẽ được gọi bởi MVC, hành động này có thể thay đổi theo định nghĩa biến

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
33 trong
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
34

NameController tên contrller đã đăng ký [xem ở trên]. Trong mục

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
35 còn có thể tự thêm các tham số riêng mà bạn sẽ đọc được bằng
return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
36

Chuỗi $routestring biểu diễn

return [
    //...
    'router' => [
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/application[/:action]',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
               ],


        ],
    //...
    ],
0 [xem đường dẫn trong cấu trúc URL ở trên] URL, nó có thể chứa các thành phần cố định và các biến. Có một số lưu ý sau

Đánh giá $routestring => '/product/[/. thể loại/. Tôi/]. html'

  • $routestring biểu diễn bởi các hằng số và các biến. If is a variable, thì có cấu trúc
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    38, as on
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    39,
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    50 is các hằng số.
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    51,
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    52 là biến tên. If is the after this variable value may be read from
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    53 see section
  • Các thành phần có thể có hoặc không có vẫn phù hợp với Tuyến đường thì có chứa trong cặp chữ cái [. ]. Như trên đó là [/. thể loại/. id/] có nghĩa là URL phù hợp phải có danh mục và id hoặc không có cả hai
  • Trong chuỗi nếu có biến có tên hành động [. action] thì nó là hành động sẽ thay đổi giá trị mặc định của
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    54. Ví dụ '/application[/. action]' if URL input is /application isphù hợp với Route and action call is action in default. Nếu đầu vào là
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    55 thì vẫn phù hợp với Route nhưng hành động gọi sẽ là
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    56
  • các ràng buộc là khu vực bạn khai báo các ràng buộc buộc phải tuân theo các biến nếu có. Các phần tử buộc phải thêm vào cú pháp
    return [
        //...
        'router' => [
            'routes' => [
                'home' => [
                    'type' => Literal::class,
                    'options' => [
                        'route'    => '/',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                ],
                'application' => [
                    'type'    => Segment::class,
                    'options' => [
                        'route'    => '/application[/:action]',
                        'defaults' => [
                            'controller' => Controller\IndexController::class,
                            'action'     => 'index',
                        ],
                    ],
                   ],
    
    
            ],
        //...
        ],
    
    57. Bạn đọc về Biểu thức chính quy RegEx để biết cấu trúc của nó. Ví dụ như
    • return [
          //...
          'router' => [
              'routes' => [
                  'home' => [
                      'type' => Literal::class,
                      'options' => [
                          'route'    => '/',
                          'defaults' => [
                              'controller' => Controller\IndexController::class,
                              'action'     => 'index',
                          ],
                      ],
                  ],
                  'application' => [
                      'type'    => Segment::class,
                      'options' => [
                          'route'    => '/application[/:action]',
                          'defaults' => [
                              'controller' => Controller\IndexController::class,
                              'action'     => 'index',
                          ],
                      ],
                     ],
      
      
              ],
          //...
          ],
      
      58 biến phải bắt đầu bởi abc, theo sau hai chữ số
    • return [
          //...
          'router' => [
              'routes' => [
                  'home' => [
                      'type' => Literal::class,
                      'options' => [
                          'route'    => '/',
                          'defaults' => [
                              'controller' => Controller\IndexController::class,
                              'action'     => 'index',
                          ],
                      ],
                  ],
                  'application' => [
                      'type'    => Segment::class,
                      'options' => [
                          'route'    => '/application[/:action]',
                          'defaults' => [
                              'controller' => Controller\IndexController::class,
                              'action'     => 'index',
                          ],
                      ],
                     ],
      
      
              ],
          //...
          ],
      
      59 biến phải bắt đầu bằng các ký tự từ a-Z, sau đó là nhóm các ký tự a-Z, 0-9 và có thể -

Use Regex Route

Loại Route này sử dụng biểu thức chính quy. Biểu thức chính quy RegEx để kiểm tra sự phù hợp của URL với Route

Chủ Đề