twohill / silverstripe-nestedcontrollers
使用嵌套控制器轻松设置前端CRUD页面的基础
v2.0.0
2019-03-08 01:29 UTC
Requires
This package is auto-updated.
Last update: 2024-09-12 18:59:12 UTC
README
为SILVERSTRIPE的嵌套控制器片段
关于
这实际上不是一个模块,但我在许多项目中都重用它,所以我认为它值得分享。它使您能够为记录(数据对象)上的操作创建逻辑URL结构。
例如,它可以用于CRUD(创建、读取、更新、删除),或以逻辑方式逐步创建对象所需的过程
例如:/mypage/people/12/edit /mypage/people/12/favourite-people
允许深入遍历相关对象
例如:/mypage/people/12/mother/uncles/43/edit
并且它允许轻松的主题覆盖。[Record]_[function].ss模板优先于[Record].ss模板。并且还有回退模板来帮助您开始。
如何使用
作为一个起点,您需要一个可以调用嵌套函数的页面。例如
<?php
class MyPage extends Page {
//...
}
class MyPage_Controller extends Page_Controller {
//..
public function people($request) {
return new PeopleCollectionController($this, $request);
}
}
这意味着每当有人调用MyPage/people时,都会使用PeopleCollectionController
。
显然您需要一个PeopleCollectionController
,让我们看看它可能的样子。
<?php
class PeopleCollectionCotroller extends NestedCollectionController {
public function favourite_people() {
// return something allowing the user to view or modify favourite people
}
}