Hello. I don't know if this is a bug or if I'm using a bad practice. I'm testing out latest pw 3.0.167.
I'm used to write this whenever I need to create a new Page from api
$p = new Page();
$p->template = 'upload';
$p->title = 'my new page';
$p->parent = 1019;
$p->save();
The following code is quite similar, yet when used inside a custom page class is generating a nasty issue.
$upload = new Page();
$upload->template = 'upload';
$upload->parent = wire()->pages->get("template=uploads");
$upload->title = time() . '-' . $email;
$upload->nome = $nome;
$upload->cognome = $cognome;
$upload->email = $email;
$upload->addStatus(Page::statusUnpublished);
$upload->save();
After execution, the admin stops working with this exception
Umm… Fatal Error: Uncaught Error: Call to a member function getPageClass() on string in wire/core/PagesLoader.php:945
#0 wire/core/PagesLoader.php (421): PagesLoader->getById(Array, NULL)
#1 wire/core/Pages.php (255): PagesLoader->find('parent_id=1019,...', Array)
#2 wire/core/Wire.php (400): Pages->___find('parent_id=1019,...', Array)
#3 wire/core/WireHooks.php (823): Wire->_callMethod('___find', Array)
#4 wire/core/Wire.php (465): WireHooks->runHooks(Object(Pages), 'find', Array)
#5 wire/core/Page.php (4577): Wire->__call('find', Array)
#6 wire/core/PageTraversal.php (130): Page- (line 945 of wire/core/PagesLoader.php)
This error message was shown because: you are logged in as a Superuser. Error has been logged.
Looking in the database, I notice that the new created page has no template assigned
If I remove that row from the db, the admin resumes working nicely.
Now if I change this
$upload->template = 'upload';
to this
$upload->template = wire()->templates->get('upload');
everything goes as expected. Any ideas?
Thank you
Leo