本文整理汇总了PHP中Page::publish方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::publish方法的具体用法?PHP Page::publish怎么用?PHP Page::publish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page::publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanViewStage
public function testCanViewStage()
{
// Create a new page
$page = new Page();
$page->URLSegment = 'testpage';
$page->write();
$page->publish('Stage', 'Live');
// Add a stage-only version
$page->Content = "Version2";
$page->write();
$response = $this->get('/testpage');
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for implicit live stage");
$response = $this->get('/testpage/?stage=Live');
$this->assertEquals($response->getStatusCode(), 200, "Doesn't require login for explicit live stage");
try {
$response = $this->get('/testpage/?stage=Stage');
} catch (SS_HTTPResponse_Exception $responseException) {
$response = $responseException->getResponse();
}
// should redirect to login
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
$this->assertContains(Config::inst()->get('Security', 'login_url'), $response->getHeader('Location'));
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$response = $this->get('/testpage/?stage=Stage');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user');
}
示例2: build
/**
* Build page from database
* @param array $data
*/
public static function build(array $data)
{
if (!isset($data['title'], $data['body'])) {
return;
}
$content = new Page($data['title'], $data['body']);
if (isset($data['stylesheets'])) {
foreach ($data['stylesheets'] as $source) {
$content->addStylesheet($source);
}
}
if (isset($data['javascripts'])) {
foreach ($data['javascripts'] as $source) {
$content->addJavascript($source);
}
}
$content->render('system.header');
if (isset($data['header'])) {
$content->setHeader($data['header']);
}
$content->render('system.footer');
if (isset($data['footer'])) {
$content->setFooter($data['footer']);
}
return $content->publish();
}
示例3: testFindOldPage
public function testFindOldPage()
{
$page = new Page();
$page->Title = 'Test Page';
$page->URLSegment = 'test-page';
$page->write();
$page->publish('Stage', 'Live');
$page->URLSegment = 'test';
$page->write();
$page->publish('Stage', 'Live');
$router = new ModelAsController();
$request = new HTTPRequest('GET', 'test-page/action/id/otherid');
$request->match('$URLSegment/$Action/$ID/$OtherID');
$response = $router->handleRequest($request);
$this->assertEquals($response->getHeader('Location'), Controller::join_links(Director::baseURL() . 'test/action/id/otherid'));
}
示例4: testDiffedChangesTitle
public function testDiffedChangesTitle()
{
$page = new Page(array('Title' => 'My Title'));
$page->write();
$page->publish('Stage', 'Live');
$page->Title = 'My Changed Title';
$page->write();
$page->publish('Stage', 'Live');
$page->Title = 'My Unpublished Changed Title';
$page->write();
// Strip spaces from test output because they're not reliably maintained by the HTML Tidier
$cleanDiffOutput = function ($val) {
return str_replace(' ', '', strip_tags($val));
};
$this->assertContains(str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'), array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')), 'Detects published title changes');
$this->assertNotContains(str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'), array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')), 'Ignores unpublished title changes');
}
示例5: setUp
public function setUp()
{
parent::setUp();
for ($i = 0; $i < 100; $i++) {
$page = new Page(array('title' => "Page {$i}"));
$page->write();
$page->publish('Stage', 'Live');
}
$sitemap = new SiteMapPage();
$sitemap->Title = 'SiteMap';
$sitemap->write();
}
示例6: testCustomSearchFormClassesToTest
function testCustomSearchFormClassesToTest() {
FulltextSearchable::enable('File');
$page = new Page();
$page->URLSegment = 'whatever';
$page->Content = 'oh really?';
$page->write();
$page->publish('Stage', 'Live');
$controller = new ContentController($page);
$form = $controller->SearchForm();
if (get_class($form) == 'SearchForm') $this->assertEquals(array('File'), $form->getClassesToSearch());
}
示例7: setUp
public function setUp()
{
parent::setUp();
// create 2 pages
for ($i = 0; $i < 2; ++$i) {
$page = new Page(array('Title' => "Page {$i}"));
$page->write();
$page->publish('Stage', 'Live');
}
// reset configuration for the test.
Config::nest();
Config::inst()->update('Foo', 'bar', 'Hello!');
}
示例8: makePages
protected function makePages($count, $depth, $prefix = "", $parentID = 0)
{
for ($i = 1; $i <= $count; $i++) {
$page = new Page();
$page->ParentID = $parentID;
$page->Title = "Test page {$prefix}{$i}";
$page->write();
$page->publish('Stage', 'Live');
echo "<li>Created '{$page->Title}'";
if ($depth > 1) {
$this->makePages($count, $depth - 1, $prefix . "{$i}.", $page->ID);
}
}
}
示例9: testCanViewStage
public function testCanViewStage()
{
$page = new Page();
$page->URLSegment = 'testpage';
$page->write();
$page->publish('Stage', 'Live');
$response = $this->get('/testpage');
$this->assertEquals($response->getStatusCode(), 200);
$response = $this->get('/testpage/?stage=Live');
$this->assertEquals($response->getStatusCode(), 200);
$response = $this->get('/testpage/?stage=Stage');
// should redirect to login
$this->assertEquals($response->getStatusCode(), 302);
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$response = $this->get('/testpage/?stage=Stage');
$this->assertEquals($response->getStatusCode(), 200);
}
示例10: testCanViewStage
public function testCanViewStage() {
$page = new Page();
$page->URLSegment = 'testpage';
$page->write();
$page->publish('Stage', 'Live');
$response = $this->get('/testpage');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for implicit live stage');
$response = $this->get('/testpage/?stage=Live');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for explicit live stage');
$response = $this->get('/testpage/?stage=Stage');
// should redirect to login
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
$this->assertContains('Security/login', $response->getHeader('Location'));
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$response = $this->get('/testpage/?stage=Stage');
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt redirect to login, but shows page for authenticated user');
}
示例11: requireDefaultRecords
public function requireDefaultRecords()
{
parent::requireDefaultRecords();
//clear all old records
$bigFmailyPages = DB::query("SELECT \"SiteTree_Live\".\"ID\" FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ClassName\" = 'BigFamilyPage'")->column();
if (count($bigFmailyPages)) {
$ids = "(" . implode(",", $bigFmailyPages) . ")";
//Delete all children from all stages
DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ParentID\" IN {$ids}");
DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"ParentID\" IN {$ids}");
DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ParentID\" IN {$ids}");
//Delete themselves from all stages
DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ID\" IN {$ids}");
DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"RecordID\" IN {$ids}");
DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ID\" IN {$ids}");
}
//create new records
$bigFamilyPages = DataObject::get('BigFamilyPage');
foreach ($bigFamilyPages as $page) {
foreach ($page->AllChildren() as $child) {
$child->delete();
}
$page->delete();
}
$familyPage = new BigFamilyPage();
$familyPage->Title = "Big Family";
$familyPage->write();
$familyPage->publish('Stage', 'Live');
foreach (singleton('Employee')->data() as $name) {
$page = new Page();
$page->Title = $name;
$page->MenuTitle = $name;
$page->ParentID = $familyPage->ID;
$page->write();
$page->publish('Stage', 'Live');
}
DB::alteration_message("Added default 'BigFamilyPage' and its children pages", "created");
}
示例12: testChildOfDraft
/**
* go to a page that's been published but is child of an unpublished page
*
* NOTE: This test requires nested_urls
*/
public function testChildOfDraft()
{
RootURLController::reset();
Config::inst()->update('SiteTree', 'nested_urls', true);
$draft = new Page();
$draft->Title = 'Root Leve Draft Page';
$draft->URLSegment = 'root';
$draft->write();
$published = new Page();
$published->Title = 'Published Page Under Draft Page';
$published->URLSegment = 'sub-root';
$published->write();
$published->publish('Stage', 'Live');
$response = $this->get('root/sub-root');
$this->assertEquals($response->getStatusCode(), 404, 'The page should not be found since its parent has not been published, in this case http://<yousitename>/root/sub-root or http://<yousitename>/sub-root');
}
示例13: Page
function testTranslationGroupNotRemovedWhenSiteTreeUnpublished()
{
$enPage = new Page();
$enPage->Locale = 'en_US';
$enPage->write();
$enPage->publish('Stage', 'Live');
$enTranslationGroup = $enPage->getTranslationGroup();
$frPage = $enPage->createTranslation('fr_FR');
$frPage->write();
$frPage->publish('Stage', 'Live');
$frTranslationGroup = $frPage->getTranslationGroup();
$enPage->doUnpublish();
$this->assertEquals($enPage->getTranslationGroup(), $enTranslationGroup);
$frPage->doUnpublish();
$this->assertEquals($frPage->getTranslationGroup(), $frTranslationGroup);
}
示例14: requireDefaultRecords
/**
* Add default records to database.
*
* This function is called whenever the database is built, after the
* database tables have all been created. Overload this to add default
* records when the database is built, but make sure you call
* parent::requireDefaultRecords().
*/
function requireDefaultRecords()
{
parent::requireDefaultRecords();
// default pages
if ($this->class == 'SiteTree' && self::$create_default_pages) {
if (!SiteTree::get_by_link('home')) {
$homepage = new Page();
$homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home');
$homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '<p>Welcome to SilverStripe! This is the default homepage. You can edit this page by opening <a href="admin/">the CMS</a>. You can now access the <a href="http://doc.silverstripe.org">developer documentation</a>, or begin <a href="http://doc.silverstripe.org/doku.php?id=tutorials">the tutorials.</a></p>');
$homepage->URLSegment = 'home';
$homepage->Status = 'Published';
$homepage->Sort = 1;
$homepage->write();
$homepage->publish('Stage', 'Live');
$homepage->flushCache();
DB::alteration_message('Home page created', 'created');
}
if (DB::query("SELECT COUNT(*) FROM \"SiteTree\"")->value() == 1) {
$aboutus = new Page();
$aboutus->Title = _t('SiteTree.DEFAULTABOUTTITLE', 'About Us');
$aboutus->Content = _t('SiteTree.DEFAULTABOUTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
$aboutus->Status = 'Published';
$aboutus->Sort = 2;
$aboutus->write();
$aboutus->publish('Stage', 'Live');
$aboutus->flushCache();
DB::alteration_message('About Us page created', 'created');
$contactus = new Page();
$contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us');
$contactus->Content = _t('SiteTree.DEFAULTCONTACTCONTENT', '<p>You can fill this page out with your own content, or delete it and create your own pages.<br /></p>');
$contactus->Status = 'Published';
$contactus->Sort = 3;
$contactus->write();
$contactus->publish('Stage', 'Live');
$contactus->flushCache();
DB::alteration_message('Contact Us page created', 'created');
}
}
// schema migration
// @todo Move to migration task once infrastructure is implemented
if ($this->class == 'SiteTree') {
$conn = DB::getConn();
// only execute command if fields haven't been renamed to _obsolete_<fieldname> already by the task
if (array_key_exists('Viewers', $conn->fieldList('SiteTree'))) {
$task = new UpgradeSiteTreePermissionSchemaTask();
$task->run(new SS_HTTPRequest('GET', '/'));
}
}
}
示例15: Page
/**
* This test ensures published Subsites Virtual Pages immediately reflect updates
* to their published target pages. Note - this has to happen when the virtual page
* is in a different subsite to the page you are editing and republishing,
* otherwise the test will pass falsely due to current subsite ID being the same.
*/
function testPublishedSubsiteVirtualPagesUpdateIfTargetPageUpdates()
{
// create page
$p = new Page();
$p->Content = 'Content';
$p->Title = 'Title';
$p->writeToStage('Stage');
$p->publish('Stage', 'Live');
$this->assertTrue($p->ExistsOnLive);
// change to subsite
$subsite = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($subsite->ID);
Subsite::$disable_subsite_filter = false;
// create svp in subsite
$svp = new SubsitesVirtualPage();
$svp->CopyContentFromID = $p->ID;
$svp->write();
$svp->writeToStage('Stage');
$svp->publish('Stage', 'Live');
$this->assertEquals($svp->SubsiteID, $subsite->ID);
$this->assertTrue($svp->ExistsOnLive);
// change back to original subsite ("Main site")
Subsite::changeSubsite(0);
// update original page
$p->Title = 'New Title';
// "save & publish"
$p->writeToStage('Stage');
$p->publish('Stage', 'Live');
$this->assertNotEquals($p->SubsiteID, $subsite->ID);
// reload SVP from database
// can't use DO::get by id because caches.
$svpdb = $svp->get()->byID($svp->ID);
// ensure title changed
$this->assertEquals($svpdb->Title, $p->Title);
}