本文整理汇总了PHP中SiteTree::get_create_default_pages方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::get_create_default_pages方法的具体用法?PHP SiteTree::get_create_default_pages怎么用?PHP SiteTree::get_create_default_pages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::get_create_default_pages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requireDefaultRecords
/**
* Ensures that there is always a 404 page
* by checking if there's an instance of
* ErrorPage with a 404 and 500 error code. If there
* is not, one is created when the DB is built.
*/
function requireDefaultRecords()
{
parent::requireDefaultRecords();
if ($this->class == 'ErrorPage' && SiteTree::get_create_default_pages()) {
// Ensure that an assets path exists before we do any error page creation
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$pageNotFoundErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '404'");
$pageNotFoundErrorPageExists = $pageNotFoundErrorPage && $pageNotFoundErrorPage->exists() ? true : false;
$pageNotFoundErrorPagePath = self::get_filepath_for_errorcode(404);
if (!($pageNotFoundErrorPageExists && file_exists($pageNotFoundErrorPagePath))) {
if (!$pageNotFoundErrorPageExists) {
$pageNotFoundErrorPage = new ErrorPage();
$pageNotFoundErrorPage->ErrorCode = 404;
$pageNotFoundErrorPage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
$pageNotFoundErrorPage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
$pageNotFoundErrorPage->write();
$pageNotFoundErrorPage->publish('Stage', 'Live');
}
// Ensure a static error page is created from latest error page content
$response = Director::test(Director::makeRelative($pageNotFoundErrorPage->Link()));
$written = null;
if ($fh = fopen($pageNotFoundErrorPagePath, 'w')) {
$written = fwrite($fh, $response->getBody());
fclose($fh);
}
if ($written) {
DB::alteration_message('404 error page created', 'created');
} else {
DB::alteration_message(sprintf('404 error page could not be created at %s. Please check permissions', $pageNotFoundErrorPagePath), 'error');
}
}
$serverErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '500'");
$serverErrorPageExists = $serverErrorPage && $serverErrorPage->exists() ? true : false;
$serverErrorPagePath = self::get_filepath_for_errorcode(500);
if (!($serverErrorPageExists && file_exists($serverErrorPagePath))) {
if (!$serverErrorPageExists) {
$serverErrorPage = new ErrorPage();
$serverErrorPage->ErrorCode = 500;
$serverErrorPage->Title = _t('ErrorPage.DEFAULTSERVERERRORPAGETITLE', 'Server error');
$serverErrorPage->Content = _t('ErrorPage.DEFAULTSERVERERRORPAGECONTENT', '<p>Sorry, there was a problem with handling your request.</p>');
$serverErrorPage->write();
$serverErrorPage->publish('Stage', 'Live');
}
// Ensure a static error page is created from latest error page content
$response = Director::test(Director::makeRelative($serverErrorPage->Link()));
$written = null;
if ($fh = fopen($serverErrorPagePath, 'w')) {
$written = fwrite($fh, $response->getBody());
fclose($fh);
}
if ($written) {
DB::alteration_message('500 error page created', 'created');
} else {
DB::alteration_message(sprintf('500 error page could not be created at %s. Please check permissions', $serverErrorPagePath), 'error');
}
}
}
}
示例2: requireDefaultRecords
/**
* Ensures that there is always a search page
* by checking if there's an instance of
* a base ExtensibleSearchPage. If there
* is not, one is created when the DB is built.
*/
function requireDefaultRecords()
{
parent::requireDefaultRecords();
if (SiteTree::get_create_default_pages()) {
$page = DataObject::get_one('ExtensibleSearchPage');
if (!($page && $page->exists())) {
$page = ExtensibleSearchPage::create();
$page->Title = _t('ExtensibleSearchPage.DEFAULT_PAGE_TITLE', 'Search Page');
$page->Content = '';
$page->ResultsPerPage = 10;
$page->Status = 'New page';
$page->write();
DB::alteration_message('Search page created', 'created');
}
}
}