PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP-控制器路由未按预期在Silverstripe 3.1中工作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在设置到控制器的路由,并且不断收到404或“ silverstripe框架入门”页面.

在routes.yaml中,我有

---
Name: nzoaroutes
After: framework/routes#coreroutes
---
Director:
  rules:
    'view-meetings/$Action/$type': 'ViewMeeting_Controller'

我的控制器如下所示:

class ViewMeeting_Controller extends Controller {

  public static $allowed_actions = array('HospitalMeetings');

  public static $url_handlers = array(
        'view-meetings/$Action/$ID' => 'HospitalMeetings'
    );

  public function init() {
    parent::init();
    if(!Member::currentUser()) {
      return $this->httpError(403);
    }
  }

  /* View a list of Hospital meetings of a specified type for this user */
  public function HospitalMeetings(SS_HTTPRequest $request) {

    print_r($arguments, 1);

  }
}

而且我创建了一个模板(ViewMeeting.ss),该模板仅输出$Content,但是当我刷新网站缓存并访问/ view-meetings / HospitalMeetings / 6?flush = 1时,

我得到认的“ Silverstripe框架入门”页面

我知道routes.yaml中的路由正在工作,因为如果我更改那里的路由并访问旧的URL,我会得到一个404,但是该请求似乎并未触发我的$Action …

解决方法:

您的YAML和控制器中有2条不同的规则($type与$ID).另外,我认为您不需要在YAML和Controller中都定义路由.

尝试此操作,YAML告诉SS将以’view-meetings’开头的所有内容发送到Controller,然后$url_handlers告诉Controller处理请求,具体取决于URL中’view-meetings’之后的所有内容.

routes.yaml

---
Name: nzoaroutes
After: framework/routes#coreroutes
---
Director:
  rules:
    'view-meetings': 'ViewMeeting_Controller'

ViewMeeting_Controller.PHP

class ViewMeeting_Controller extends Controller {

  private static $allowed_actions = array('HospitalMeetings');

  public static $url_handlers = array(
      '$Action/$type' => 'HospitalMeetings'
  );

  public function init() {
    parent::init();
    if(!Member::currentUser()) {
      return $this->httpError(403);
    }
  }

  public function HospitalMeetings(SS_HTTPRequest $request) {
  }
}

大佬总结

以上是大佬教程为你收集整理的PHP-控制器路由未按预期在Silverstripe 3.1中工作全部内容,希望文章能够帮你解决PHP-控制器路由未按预期在Silverstripe 3.1中工作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: