dynamic/viewable-dataobject
最新稳定版本:2.0.0-beta2
Composer 安装命令:
composer require dynamic/viewable-dataobject
包简介
DataExtension that easily allows a DataObject to be viewed like a Page
README 文档
README
DataExtension that easily allows a dataobject to be viewed like a Page
Requirements
- SilverStripe ^4.0
Installation
composer require dynamic/viewable-dataobject
In config.yml:
MyDataObject: extensions: - Dynamic\ViewableDataObject\Extensions\ViewableDataObject
Example usage
On the DataObject you'd like to view as a page:
<?php use Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface; class MyDataObject extends DataObject implements ViewableDataObjectInterface { public function getParentPage() { return MyDisplayPage::get()->first(); } public function getViewAction() { return 'myobject'; } }
On the Page_Controller you'd like to view your DataObject:
<?php use SilverStripe\Control\HTTPRequest; use SilverStripe\View\ArrayData; class MyDisplayPageController extends \PageController { public function myobject(HTTPRequest $request) { $urlSegment = $request->latestParam('ID'); if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) { return $this->httpError(404, "The object you're looking for doesn't seem to be here."); } return $this->customise(new ArrayData([ 'Object' => $object, 'Title' => $object->Title, 'MetaTags' => $object->MetaTags(false), 'Breadcrumbs' => $object->Breadcrumbs(), ])); } }
Controller Extension
Adding the controller extension to a class will allow for using custom layout templates.
In config.yml:
MyControler: extensions: - Dynamic\ViewableDataObject\Extensions\ControllerExtension
Instead of calling render, renderWith, or customize; renderWithLayout can be passed a list of layout templates and extra data.
<?php use SilverStripe\Control\HTTPRequest; class MyDisplayPageController extends \PageController { public function myobject(HTTPRequest $request) { $urlSegment = $request->latestParam('ID'); if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) { return $this->httpError(404, "The object you're looking for doesn't seem to be here."); } return $this->renderWithLayout([ MyDataObject::class, MyDisplayPage::class, ], [ 'Object' => $object, 'Title' => $object->Title, 'MetaTags' => $object->MetaTags(false), 'Breadcrumbs' => $object->Breadcrumbs(), ]); } }
renderWithLayout will add \Page::class to the end of the template list.
The first valid template in the array will be used.
统计信息
- 总下载量: 11.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-01-12