有人可以解释一下 Silverstripe 4 中的操作是如何工作的吗?
我有这样的控制器:
<?php
use SilverStripe\Control\HTTPRequest;
class ShopHolderPageController extends PageController
{
private static $allowed_actions = [
'add-shop'
];
private static $url_handlers = [
'add-shop' => 'shopForm'
];
protected function init()
{
parent::init();
}
public function shopForm(HTTPRequest $request)
{
return 'test';
}
}
当我在浏览器中启动它时,我得到了这个:
Debug (line 261 of RequestHandler.php): Testing 'add-shop' with 'add-shop' on ShopHolderPageController
Debug (line 271 of RequestHandler.php): Rule 'add-shop' matched to action 'shopForm' on ShopHolderPageController. Latest request params: array ( )
Debug (line 261 of RequestHandler.php): Testing '$Action//$ID/$OtherID' with '' on SilverStripe\ErrorPage\ErrorPageController
Debug (line 271 of RequestHandler.php): Rule '$Action//$ID/$OtherID' matched to action 'handleAction' on SilverStripe\ErrorPage\ErrorPageController. Latest request params: array ( 'Action' => NULL, 'ID' => NULL, 'OtherID' => NULL, )
Debug (line 185 of RequestHandler.php): Action not set; using default action method name 'index'
Debug (line 234 of Controller.php): Request handler returned HTTPResponse object to ShopHolderPageController controller;returning it without modification.
我不明白为什么在 RequestHandler 将规则“add-shop”与操作“shopForm”匹配之后,控制器没有执行“shopForm”操作。它没有执行找到的操作,而是调用 errorPageController...