本文整理汇总了PHP中Page::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::write方法的具体用法?PHP Page::write怎么用?PHP Page::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page::write方法的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: importItem
protected function importItem($item, $parentObject, $duplicateStrategy)
{
if ($item) {
$externalId = $item->getExternalId();
$parentFilter = $parentObject ? ' AND "ParentID" = ' . (int) $parentObject->ID : '';
$existing = DataObject::get_one('Page', '"MetaTitle" = \'' . $externalId . '\'' . $parentFilter);
if ($existing && $existing->exists()) {
if ($duplicateStrategy == ExternalContentTransformer::DS_SKIP) {
return;
}
if ($duplicateStrategy == ExternalContentTransformer::DS_DUPLICATE) {
$existing = new Page();
}
} else {
$existing = new Page();
}
$existing->Title = 'Tweet: ' . $item->Title;
$existing->MetaTitle = $externalId;
$existing->Content = $item->Tweet;
if ($parentObject) {
$existing->ParentID = $parentObject->ID;
}
$existing->write();
$existing->Created = date('Y-m-d H:i:s', strtotime($item->Created));
$existing->LegacyURL = $item->Link;
$existing->MetaDescription = 'Tweet from ' . $item->CreatedBy . ' at ' . $item->Created;
$existing->write();
return $existing;
}
}
示例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: testReadOnlyTransaction
function testReadOnlyTransaction()
{
if (DB::get_conn()->supportsTransactions() == true && DB::get_conn() instanceof PostgreSQLDatabase) {
$page = new Page();
$page->Title = 'Read only success';
$page->write();
DB::get_conn()->transactionStart('READ ONLY');
try {
$page = new Page();
$page->Title = 'Read only page failed';
$page->write();
} catch (Exception $e) {
//could not write this record
//We need to do a rollback or a commit otherwise we'll get error messages
DB::get_conn()->transactionRollback();
}
DB::get_conn()->transactionEnd();
DataObject::flush_and_destroy_cache();
$success = DataObject::get('Page', "\"Title\"='Read only success'");
$fail = DataObject::get('Page', "\"Title\"='Read only page failed'");
//This page should be in the system
$this->assertTrue(is_object($success) && $success->exists());
//This page should NOT exist, we had 'read only' permissions
$this->assertFalse(is_object($fail) && $fail->exists());
} else {
$this->markTestSkipped('Current database is not PostgreSQL');
}
}
示例5: testCreateWithTransaction
function testCreateWithTransaction()
{
if (DB::getConn()->supportsTransactions() == true) {
DB::getConn()->transactionStart();
$page = new Page();
$page->Title = 'First page';
$page->write();
$page = new Page();
$page->Title = 'Second page';
$page->write();
//Create a savepoint here:
DB::getConn()->transactionSavepoint('rollback');
$page = new Page();
$page->Title = 'Third page';
$page->write();
$page = new Page();
$page->Title = 'Forth page';
$page->write();
//Revert to a savepoint:
DB::getConn()->transactionRollback('rollback');
DB::getConn()->transactionEnd();
$first = DataObject::get('Page', "\"Title\"='First page'");
$second = DataObject::get('Page', "\"Title\"='Second page'");
$third = DataObject::get('Page', "\"Title\"='Third page'");
$forth = DataObject::get('Page', "\"Title\"='Forth page'");
//These pages should be in the system
$this->assertTrue(is_object($first) && $first->exists());
$this->assertTrue(is_object($second) && $second->exists());
//These pages should NOT exist, we reverted to a savepoint:
$this->assertFalse(is_object($third) && $third->exists());
$this->assertFalse(is_object($forth) && $forth->exists());
} else {
$this->markTestSkipped('Current database does not support transactions');
}
}
示例6: pageIsBrokenFile
protected function pageIsBrokenFile($content)
{
$page = new Page();
$page->Content = $content;
$page->write();
return $page->HasBrokenFile;
}
示例7: requireDefaultRecords
function requireDefaultRecords()
{
if ($this->class == 'TestPage') {
return;
}
$class = $this->class;
if (!DataObject::get_one($class)) {
// Try to create common parent
$parent = SiteTree::get()->filter('URLSegment', 'feature-test-pages')->First();
if (!$parent) {
$parent = new Page(array('Title' => 'Feature Test Pages', 'Content' => 'A collection of pages for testing various features in the SilverStripe CMS', 'ShowInMenus' => 0));
$parent->write();
$parent->doPublish();
}
// Create actual page
$page = new $class();
$page->Title = str_replace("TestPage", "", $class);
$page->ShowInMenus = 0;
if ($parent) {
$page->ParentID = $parent->ID;
}
$page->write();
$page->publish('Stage', 'Live');
}
}
示例8: testReadOnlyTransaction
function testReadOnlyTransaction()
{
if (DB::getConn()->supportsTransactions() == true) {
$page = new Page();
$page->Title = 'Read only success';
$page->write();
DB::getConn()->startTransaction('READ ONLY');
try {
$page = new Page();
$page->Title = 'Read only page failed';
$page->write();
} catch (Exception $e) {
//could not write this record
//We need to do a rollback or a commit otherwise we'll get error messages
DB::getConn()->transactionRollback();
}
DB::getConn()->endTransaction();
$success = DataObject::get('Page', "\"Title\"='Read only success'");
$fail = DataObject::get('Page', "\"Title\"='Read only failed'");
//This page should be in the system
$this->assertTrue(is_object($success) && $success->exists());
//This page should NOT exist, we had 'read only' permissions
$this->assertFalse(is_object($fail) && $fail->exists());
}
}
示例9: run
function run($request)
{
$id = $request->getVar('ID');
if (!is_numeric($id) && !preg_match('/^[0-9]+_[0-9]+$/', $id) || !$id) {
echo "<p>Specify ?ID=(number) or ?ID=(ID)_(Code)</p>\n";
return;
}
$includeSelected = false;
$includeChildren = true;
$duplicates = 'Duplicate';
$selected = $id;
$target = new Page();
$target->Title = "Import on " . date('Y-m-d H:i:s');
$target->write();
$targetType = 'SiteTree';
$from = ExternalContent::getDataObjectFor($selected);
if ($from instanceof ExternalContentSource) {
$selected = false;
}
$importer = null;
$importer = $from->getContentImporter($targetType);
if ($importer) {
$importer->import($from, $target, $includeSelected, $includeChildren, $duplicates);
}
}
开发者ID:helpfulrobot,项目名称:silverstripe-staticsiteconnector,代码行数:25,代码来源:ExternalContentImportContentTask.php
示例10: 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');
}
示例11: testCreateNewContent
public function testCreateNewContent()
{
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$mid = Member::currentUserID();
// create some content and make a change. When saving, it should be added to the current user's
// active changeset
$obj = new Page();
$obj->Title = "New Page";
$obj->write();
// it should have a changeset now
$cs1 = $obj->getCurrentChangeset();
$this->assertNotNull($cs1);
$obj->Title = "New Page Title";
$obj->write();
$cs1 = $obj->getCurrentChangeset();
$this->assertNotNull($cs1);
$this->assertEquals(1, $cs1->getItems()->Count());
$this->assertEquals("Active", $cs1->Status);
}
示例12: testPageURL
public function testPageURL()
{
$page = new Page();
$page->URLSegment = 'test';
$page->write();
$obj = new LinkFieldTest_DataObject();
$obj->Link->setPageID($page->ID);
$obj->write();
$this->assertEquals($page->Link(), $obj->Link->URL);
}
示例13: 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();
}
示例14: 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());
}
示例15: 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!');
}