【发布时间】:2014-05-20 09:36:54
【问题描述】:
我在让模板处理工作时遇到了一些问题...我创建了一个控制器(没有页面,比如这里:http://www.ssbits.com/tutorials/2011/controllers-instead-of-pages/)
现在我想让 url /package/something/something_else 映射到索引函数并显示 PackageController_index.ss 模板(package 是我使用 Director::addRules 为该控制器赋予的 slug 的名称)。这不起作用,Silverstripe 显示 404。/package/test 确实有效,它显示了 PackageController_test.ss 模板。
奇怪的是,/package/something/something_else 最终会出现在 de 控制器的 index 函数中,因为在 index 函数中取消注释该行会显示文本。
有人知道如何解决这个问题或我在这里做错了什么吗?我正在使用版本 3.1.4 3.1.5.
class PackageController extends Page_Controller {
static $allowed_actions = array(
'index',
'test',
'$PackageID/$PackageName/',
);
protected static $url_handlers = array(
'test' => 'test',
'$PackageID/$PackageName/' => 'index',
);
public function init() {
parent::init();
// Requirements, etc. here
}
public function index() {
//echo "woohoo!;die; //uncommenting this one shows "woohoo!"
return array();
}
public function test() {
return array();
}
}
更新:我启用了 debug_request,这就是我在 index() 中取消注释该行时得到的结果:
Debug (line 250 of RequestHandler.php): Testing 'test' with 'test3/test4' on PackageController
Debug (line 250 of RequestHandler.php): Testing 'filter' with 'test3/test4' on PackageController
Debug (line 250 of RequestHandler.php): Testing '$PackageID/$PackageName/' with 'test3/test4' on PackageController
Debug (line 258 of RequestHandler.php): Rule '$PackageID/$PackageName/' matched to action 'index' on PackageController. Latest request params: array ( 'PackageID' => 'test3', 'PackageName' => 'test4', )
woohoo!
当我再次评论该行时,会发生这种情况:
Debug (line 250 of RequestHandler.php): Testing 'test' with 'test3/test3' on PackageController
Debug (line 250 of RequestHandler.php): Testing 'filter' with 'test3/test3' on PackageController
Debug (line 250 of RequestHandler.php): Testing '$PackageID/$PackageName/' with 'test3/test3' on PackageController
Debug (line 258 of RequestHandler.php): Rule '$PackageID/$PackageName/' matched to action 'index' on PackageController. Latest request params: array ( 'PackageID' => 'test3', 'PackageName' => 'test3', )
Debug (line 250 of RequestHandler.php): Testing '$Action//$ID/$OtherID' with '' on ErrorPage_Controller
Debug (line 258 of RequestHandler.php): Rule '$Action//$ID/$OtherID' matched to action 'handleAction' on ErrorPage_Controller. Latest request params: array ( 'Action' => NULL, 'ID' => NULL, 'OtherID' => NULL, )
Debug (line 184 of RequestHandler.php): Action not set; using default action method name 'index'
更新 2:我尝试更新到 3.1.5,但无济于事。
【问题讨论】: