Skip to content

Custom Page Class: Creating Pages with new Page() Not Visible in Admin Interface #1864

@klor

Description

@klor

Short description of the issue

When using the createPage method in a custom class that extends Page, the instantiation of the Page object using $p = new Page(); is not working as expected, even though it should. The issue is that the created page is not visible in the ProcessWire admin interface, although it is stored in the database.

<?php namespace ProcessWire;

class ProductPage extends Page {

	public function createPage($array) {
		$pages = $this->wire('pages');

		$p = new Page();
		$p->setOutputFormatting(false);
		$p->template = 'my-template'; // valid template
		$p->parent = $pages->get('/foo/'); // parent exists, template family allows 'my-template'
		$p->name = 'bar';
		$p->title = 'bar';
		$p->save();
	}
}

Expected behavior

The createPage method should successfully create a new page with the specified template, parent, name, and title, and it should be visible in the ProcessWire admin interface.

Actual behavior

  1. The created page is not visible in the ProcessWire admin interface, even though it is stored in the database.
  2. The code works when executed from '/site/templates/my-template.php' (a page is created).

Optional: Screenshots/Links that demonstrate the issue

N/A

Optional: Suggestion for a possible fix

Your possible fix goes here.

Steps to reproduce the issue

  1. Create a custom class that extends Page with a createPage method, similar to the code provided in the issue description.
  2. Instantiate the custom class and call the createPage method.
  3. Check the ProcessWire admin interface to see that the created page is not visible.

Setup/Environment

  • ProcessWire version: 3.0.229
  • PHP version: 8.2
  • MySQL version: 10.6.13-MariaDB
  • 3rd party modules: TracyDebugger, ProcessWireUpgrade, ProcessDatabaseBackups, ImportPagesCSV

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions