navidonskis / silverstripe-datapages
此包已被弃用且不再维护。未建议替代包。
此包最新版本(dev-master)无可用许可证信息。
数据页面是SilverStripe CMS模块,用于创建面向对象的页面
dev-master
2017-08-02 11:04 UTC
Requires
This package is not auto-updated.
Last update: 2022-06-21 13:53:57 UTC
README
这是一个模块(包),作为创建具有元标签、URL段、链接等可链接数据对象的辅助工具。
使用方法
要创建自己的链接对象,以下是一个简单的产品对象的示例
// Product.php class Product extends DataPage { private static $db = []; // your own options } // ProductListingPage.php class ProductListingPage extends Page { // list of the products public function getProducts() { return Product::get(); } // override MetaTags to get from Product public function MetaTags($includeTitle = true) { $segment = Controller::curr()->getRequest()->param('URLSegment'); if ($product = Product::getByUrlSegment($segment)) { return $product->MetaTags($includeTitle); } return parent::MetaTags($includeTitle); } } // ProductListingPage.php class ProductListingPage_Controller extends Page_Controller { private static $allowed_actions = ['product']; private static $url_handlers = [ '' => 'index', '$URLSegment!' => 'product' ]; public function product(SS_HTTPRequest $request) { $segment = $request->param('URLSegment'); if (($product = Product::getByUrlSegment($segment)) && $product instanceof Product && $product->canView()) { $this->Title = $product->Title; return $this->renderWith(['ProductListingPage_product', 'Page'], [ 'Title' => $product->Title, 'Content' => DBField::create_field('HTMLText', $product->Content), 'Pictures' => $product->Pictures(), ]); } $this->httpError(404); } }
<!-- ProductListingPage.ss --> <div class="container"> <article> <% if $Title %><h1>$Title</h1><% end_if %> <div class="content"> $Content <div class="products"> <% loop $Products %> <div class="products__item" id="$URLSegment"> <a href="$Link"><h2>$Title</h2></a> $Summary </div> <% end_loop %> </div> </div> </article> $Form </div> <!-- ProductListingPage_product.ss --> <div class="container"> <article> <% if $Title %><h1>$Title</h1><% end_if %> <div class="content"> $Content </div> </article> </div>
使对象可搜索
将此配置添加到您的 config.yml
以使 DataPage
具有全文搜索功能。
DataPage: indexes: SearchFields: type: fulltext name: SearchFields value: '"Title", "Content", "MenuTitle", "MetaDescription", "MetaKeywords"' create_table_options: MySQLDatabase: 'ENGINE=MyISAM'