本文整理汇总了PHP中ErrorPage::requireDefaultRecords方法的典型用法代码示例。如果您正苦于以下问题:PHP ErrorPage::requireDefaultRecords方法的具体用法?PHP ErrorPage::requireDefaultRecords怎么用?PHP ErrorPage::requireDefaultRecords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorPage
的用法示例。
在下文中一共展示了ErrorPage::requireDefaultRecords方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requireDefaultRecords
/**
* Create default Utility Page setup
* Ensures that there is always a 503 Utility page by checking if there's an
* instance of ErrorPage with a 503 error code. If there is not,
* one is created when the DB is built.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Skip creation of default records
if (!self::config()->create_default_pages) {
return;
}
//Only create a UtilityPage on dev/build if one does not already exist.
if (!UtilityPage::get()->exists()) {
$page = UtilityPage::create(array('Title' => _t('MaintenanceMode.TITLE', 'Undergoing Scheduled Maintenance'), 'URLSegment' => _t('MaintenanceMode.URLSEGMENT', 'offline'), 'MenuTitle' => _t('MaintenanceMode.MENUTITLE', 'Utility Page'), 'Content' => _t('MaintenanceMode.CONTENT', '<h1>We’ll be back soon!</h1>' . '<p>Sorry for the inconvenience but ' . 'our site is currently down for scheduled maintenance. ' . 'If you need to you can always <a href="mailto:#">contact us</a>, ' . 'otherwise we’ll be back online shortly!</p>' . '<p>— The Team</p>'), 'ParentID' => 0, 'Status' => 'Published'));
$page->write();
$page->publish('Stage', 'Live');
DB::alteration_message('Utility Page created', 'created');
}
}
示例2: requireDefaultRecords
/**
* Create default Utility Page setup
* Ensures that there is always a 503 Utility page by checking if there's an
* instance of ErrorPage with a 503 error code. If there is not,
* one is created when the DB is built.
*/
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
// Skip creation of default records
if (!self::config()->create_default_pages) {
return;
}
// Ensure that an assets path exists before we do any error page creation
if (!file_exists(ASSETS_PATH)) {
mkdir(ASSETS_PATH);
}
$code = self::$defaults['ErrorCode'];
$pagePath = self::get_filepath_for_errorcode($code);
$page = UtilityPage::get()->first();
$pageExists = $page && $page->exists();
//Only create a UtilityPage on dev/build if one does not already exist.
if (!$pageExists || !file_exists($pagePath)) {
if (!$pageExists) {
$page = UtilityPage::create(array('Title' => _t('MaintenanceMode.TITLE', 'Undergoing Scheduled Maintenance'), 'URLSegment' => _t('MaintenanceMode.URLSEGMENT', 'offline'), 'MenuTitle' => _t('MaintenanceMode.MENUTITLE', 'Utility Page'), 'Content' => _t('MaintenanceMode.CONTENT', '<h1>We’ll be back soon!</h1>' . '<p>Sorry for the inconvenience but ' . 'our site is currently down for scheduled maintenance. ' . 'If you need to you can always <a href="mailto:#">contact us</a>, ' . 'otherwise we’ll be back online shortly!</p>' . '<p>— The Team</p>'), 'ParentID' => 0, 'Status' => 'Published'));
$page->write();
$page->publish('Stage', 'Live');
}
// Ensure a static error page is created from latest Utility Page content
$response = Director::test(Director::makeRelative($page->Link()));
$written = null;
if ($fh = fopen($pagePath, 'w')) {
$written = fwrite($fh, $response->getBody());
fclose($fh);
}
if ($written) {
DB::alteration_message(sprintf('%s error Utility Page created', $code), 'created');
} else {
DB::alteration_message(sprintf('%s error Utility page could not be created at %s. Please check permissions', $code, $pagePath), 'error');
}
}
}