簡體   English   中英

如果 controller 在文件夾內,Yii2 路由配置?

[英]Yii2 route config if controller inside folder?

在此處輸入圖像描述

this image are my yii2 project structure, i already config routes to access these controllers, some routes with controller in top level of controller folder working well(green color), but not working in controller inside sub folder (red color).

目標

URL(綠色): /{storeId}/{controller}/{action} -> 運行良好

URL(紅色): /{storeId}/{folder}/{controller}/{action} ->不工作(顯示未找到消息)

如何解決這個問題?,我不知道並且已經在谷歌上搜索但沒有運氣。 預先感謝。

按照 Yii 中的約定,所有控制器都存放在同一個目錄下,即controllers中,不能使用子目錄。 但是,您可以使用modules 在您的目錄結構中:

...
controllers
models
modules
  product
    controllers
      InboundController.php
      OutboundController.php
    models
    Module.php
    views
  report
    controllers
      PurchaseController.php
      SalesController.php
      StockController.php
    models
    Module.php
    views
runtime
...

請參閱Yii 文檔 配置 Module.php,按照那里的描述進行引導。

您可以在您的 routes.php 中使用以下路由:

'<store:\w+>/<module:\w+>/<controller:[\w\-]+>/<action:[\w\-]+>' => '<module>/<controller>/<action>'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM