本文整理汇总了PHP中PageModel::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP PageModel::exists方法的具体用法?PHP PageModel::exists怎么用?PHP PageModel::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PageModel
的用法示例。
在下文中一共展示了PageModel::exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateBlog
/**
* Create a new blog
*/
public function testCreateBlog()
{
// Setup some variables that will be used throughout this method.
$random = Core::RandomHex(6);
$title = 'New Test Blog ' . Core::RandomHex(6);
// Update the current user so it has admin access.
\Core\user()->set('admin', true);
$request = new PageRequest('/blog/create');
// Run the method, it should give me a 200 since the user is now an admin.
$request->execute();
$view = $request->getView();
$this->assertEquals(200, $view->error, 'Checking that admin users can create blogs');
// The returned data should have a "form" available. This is the actual creation form.
/** @var $form Form */
$form = $view->getVariable('form');
$this->assertInstanceOf('Form', $form, 'Checking that the form is set from the blog create controller');
// Set some variables on the form
$form->getElement('page[title]')->set('value', $title);
$form->getElement('page[rewriteurl]')->set('value', '/blogtest-' . $random);
// And submit this form to the handler.
// On a successful submission, it should be simply the URL of the blog.
$formsubmission = call_user_func_array($form->get('callsmethod'), array($form));
$this->assertStringStartsWith('/blog/view/', $formsubmission, 'Checking that form creation was successful');
self::$TestBlogID = substr($formsubmission, 11);
// This will be just the number at the end of the baseurl, ie: the id.
// Make sure that this blog exists!
$blog = new BlogModel(self::$TestBlogID);
$this->assertTrue($blog->exists(), 'Checking that blog model creation was successful');
// And make sure that the page was created.
$page = new PageModel('/blog/view/' . self::$TestBlogID);
$this->assertTrue($page->exists(), 'Checking that blog page creation was successful');
// Go to the page and make sure that it loads up!
$request = new PageRequest('/blog/view/' . self::$TestBlogID);
$request->execute();
$view = $request->getView();
$this->assertEquals(200, $view->error, 'Checking that public blog page exists');
$html = $view->fetch();
$this->assertContains($title, $html, 'Checking that the public blog page contains the correct title');
}
示例2: page_unpublish
/**
* Shortcut for unpublishing a page.
*/
public function page_unpublish() {
$view = $this->getView();
$request = $this->getPageRequest();
if(!\Core\user()->checkAccess('p:/core/pages/manage')){
return View::ERROR_ACCESSDENIED;
}
$baseurl = $request->getParameter('baseurl');
$page = new PageModel($baseurl);
if(!$page->exists()){
return View::ERROR_NOTFOUND;
}
if(!$request->isPost()){
return View::ERROR_BADREQUEST;
}
// Is this page already un-published?
if($page->get('published_status') == 'draft'){
\Core\set_message('t:MESSAGE_ERROR_PAGE_ALREADY_UNPUBLISHED');
\Core\go_back();
}
$page->set('published_status', 'draft');
$page->save();
\Core\set_message('t:MESSAGE_SUCCESS_PAGE_UNPUBLISHED');
\Core\go_back();
}
示例3: getPageModel
/**
* Get the page model for the current page.
*
* @return PageModel
*/
public function getPageModel() {
if ($this->_pagemodel === null) {
$uri = $this->uriresolved;
$pagefac = new ModelFactory('PageModel');
$pagefac->where('rewriteurl = ' . $uri);
//$pagefac->where('fuzzy = 0');
$pagefac->limit(1);
if(Core::IsComponentAvailable('multisite') && MultiSiteHelper::IsEnabled()){
$pagefac->whereGroup('OR', array('site = -1', 'site = ' . MultiSiteHelper::GetCurrentSiteID()));
}
$p = $pagefac->get();
// Split this URL, it'll be used somewhere.
$pagedat = $this->splitParts();
if ($p) {
// :) Found it
$this->_pagemodel = $p;
}
elseif ($pagedat && isset($pagedat['baseurl'])) {
// Is this even a valid controller?
// This will allow a page to be called with it being in the pages database.
$p = new PageModel($pagedat['baseurl']);
if(!$p->exists()){
$p->set('rewriteurl', $pagedat['rewriteurl']);
}
$this->_pagemodel = $p;
}
else {
// No page in the database and no valid controller... sigh
$this->_pagemodel = new PageModel();
}
//var_dump($p); die();
// Make sure all the parameters from both standard GET and core parameters are tacked on.
if ($pagedat && $pagedat['parameters']) {
foreach ($pagedat['parameters'] as $k => $v) {
$this->_pagemodel->setParameter($k, $v);
}
}
if (is_array($_GET)) {
foreach ($_GET as $k => $v) {
if (is_numeric($k)) continue;
$this->_pagemodel->setParameter($k, $v);
}
}
}
return $this->_pagemodel;
}
示例4: testAdmin
public function testAdmin(){
// Basic Construct should return one result.
/** @var PageModel $page */
$page = PageModel::Construct('/admin');
$this->assertInstanceOf('Model', $page);
$this->assertInstanceOf('PageModel', $page);
if(!$page->exists()){
$this->markTestSkipped('/admin page does not exist, Core must not be installed.');
return;
}
// Test that getAsArray works as expected.
$asArray = $page->getAsArray();
$this->assertInternalType('array', $asArray);
$this->assertGreaterThan(0, sizeof($asArray));
// And JSON
$asJSON = $page->getAsJSON();
$this->assertInternalType('string', $asJSON);
$this->assertGreaterThan(0, strlen($asJSON));
$this->assertInternalType('array', json_decode($asJSON, true));
$this->assertArrayHasKey('title', $asArray);
$this->assertArrayHasKey('title', $page);
$this->assertEquals($asArray['title'], $page->get('title'));
$this->assertArrayHasKey('expires', $asArray);
$this->assertArrayHasKey('expires', $page);
$this->assertEquals($asArray['expires'], $page->get('expires'));
// Test that getLink behaves as expected.
$this->assertNull($page->getLink('nonexistent'));
// Pages also have the following linked records,
// insertables, pagemetas, and rewrites.
$this->assertInternalType('array', $page->getLink('Insertable'));
$this->assertInternalType('array', $page->getLink('PageMeta'));
$this->assertInternalType('array', $page->getLink('RewriteMap'));
// Ensure that creating meta files works
$meta_name = 'phpunit-test';
$meta_val = 'This is a test meta field from phpunit';
$page->setMeta($meta_name, $meta_val);
// Saving the page should also save this new meta.
$this->assertTrue($page->save());
// Verify this meta from a separate object
// (because Construct will use the cached copy)
$page2 = new PageModel('/admin');
$this->assertTrue($page2->exists());
$this->assertEquals($meta_val, $page2->getMetaValue($meta_name));
// Remove the field from the original object now.
$page->setMeta($meta_name, null);
// Test that removing it does not remove the object's data until the parent is saved though!
$meta = new PageMetaModel($page->get('site'), $page->get('baseurl'), $meta_name, '');
$this->assertTrue($meta->exists());
$this->assertTrue($page->save());
$meta = new PageMetaModel($page->get('site'), $page->get('baseurl'), $meta_name, '');
$this->assertFalse($meta->exists());
}
示例5: _parsePages
/**
* Internal function to parse and handle the configs in the component.xml file.
* This is used for installations and upgrades.
*
* @param boolean $install Set to false to force uninstall/disable mode.
* @param int $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
*
* @return boolean | int
* @throws InstallerException
*/
public function _parsePages($install = true, $verbosity = 0) {
$changes = array();
$overallAction = $install ? 'Installing' : 'Uninstalling';
Core\Utilities\Logger\write_debug($overallAction . ' pages for ' . $this->getName());
// I need to get the schema definitions first.
$node = $this->_xmlloader->getElement('pages');
//$prefix = $node->getAttribute('prefix');
// Now, get every table under this node.
foreach ($node->getElementsByTagName('page') as $subnode) {
/** @var DomElement $subnode */
$baseurl = $subnode->getAttribute('baseurl');
// Insert/Update the defaults for an entry in the database.
// These are always global pages.
$m = new PageModel(-1, $baseurl);
if($verbosity == 2){
CLI::PrintActionStart($overallAction . ' page ' . $baseurl);
}
// Hard-set pages get removed upon disabling. They'll be recreated if re-enabled.
if($install){
// Just something to help the log.
$action = ($m->exists()) ? 'Updated' : 'Added';
$admin = $subnode->getAttribute('admin');
$selectable = ($admin ? '0' : '1'); // Defaults
$group = ($admin ? $subnode->getAttribute('group') : '');
if($subnode->getAttribute('selectable') !== ''){
$selectable = $subnode->getAttribute('selectable');
}
$indexable = ($subnode->getAttribute('indexable') !== '') ? $subnode->getAttribute('indexable') : $selectable;
$editurl = $subnode->getAttribute('editurl') ? $subnode->getAttribute('editurl') : '';
$access = ($subnode->getAttribute('access')) ? $subnode->getAttribute('access') : null;
// Do not "update" value, keep whatever the user set previously.
if (!$m->get('rewriteurl')) {
if ($subnode->getAttribute('rewriteurl')) $m->set('rewriteurl', $subnode->getAttribute('rewriteurl'));
else $m->set('rewriteurl', $subnode->getAttribute('baseurl'));
}
// Do not "update" value, keep whatever the user set previously.
if (!$m->get('title')) $m->set('title', $subnode->getAttribute('title'));
if($access !== null){
$m->set('access', $access);
}
// Do not update parent urls if the page already exists.
if(!$m->exists()) $m->set('parenturl', $subnode->getAttribute('parenturl'));
//$m->set('widget', $subnode->getAttribute('widget'));
$m->set('admin', $admin);
$m->set('admin_group', $group);
$m->set('selectable', $selectable);
$m->set('indexable', $indexable);
$m->set('component', $this->getKeyName());
$m->set('editurl', $editurl);
if ($m->save()){
$changes[] = $action . ' page [' . $baseurl . ']';
if($verbosity == 2){
CLI::PrintActionStatus(true);
}
}
else{
if($verbosity == 2){
CLI::PrintActionStatus('skip');
}
}
}
else{
$m->delete();
$changes[] = 'Removed page [' . $subnode->getAttribute('baseurl') . ']';
if($verbosity == 2){
CLI::PrintActionStatus(true);
}
}
}
return ($changes > 0) ? $changes : false;
}