New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting a custom User class results in fatal error #1325
Comments
I don't get a problem with a custom User class as per the instructions in the blog post: https://processwire.com/blog/posts/pw-3.0.152/#new-ability-to-specify-custom-page-classes /site/classes/UserPage.php <?php namespace ProcessWire;
class UserPage extends User {
public function greeting() {
return 'hello';
}
} The blog post doesn't say anything about editing the user template and changing its class so I'm not sure why you're doing those steps. |
@Toutouwai Fair enough, it works this way. However, for every other template my approach (editing the Page class name setting for the template) works fine, and I prefer it. The approach mentioned in the blog post has some limitations I don't like:
I'm not saying that the simpler approach using |
@schwarzdesign This is a setting that requires But theoretically it should still be possible to override it as long as it's extending the User class. I can see your example does that, but the error message seems to indicate that it was dealing with just a Page instance rather than a User instance. That makes me think that PW just doesn't know about your MemberUser class soon enough in order to use it. This could be because identifying the user happens early in the boot process, before the init() state, and very likely before your custom class is visible to PW. I think that if you made your custom class visible from /site/config.php (by including it from there) then it just might work. |
@ryancramerdesign Thanks for the reply! My custom classes are autoloaded using Composer's autoloader. However, the autoloader was included in I tried including the autoloader in the
This error comes from
In the database, the custom class is saved with double backslashes like this: Could you take a look if this is something that can be fixed? I'm thinking this is the last hurdle, and it would be really great if this use-case could be supported. Extending the Thanks! |
@schwarzdesign Thanks for the additional info. In the file /wire/core/PagesType.php can you try changing this line (607):
to this (just change the false to true):
Does that fix the issue? |
@ryancramerdesign Looks like it's working, thanks! With this change the errors are gone and ProcessWire appears to correctly use the extended class: Source code for the extended class for testing: <?php
namespace schwarzdesign\Page;
use ProcessWire\User;
class MemberUser extends User {
public function sayHello() {
return 'Hello World :)';
}
} Can you include this change in the core? Really glad it's working now. Thanks again! |
@schwarzdesign Thanks for testing that out, glad it fixes it there too. I've pushed the change to the dev branch. |
Great addition, thanks @ryancramerdesign! |
Short description of the issue
Using custom page classes with the
user
template results in a fatal error. As per this blog post, it should be possible to extend the default\ProcessWire\User
class with a custom class and configure ProcessWire to use the custom class for$user
objects. However, this results in a fatal error when I try it.Expected behavior
Using a custom class extending the
User
class for theuser
template should not cause an error.In addition, when setting a custom class for the
user
template and this error occurs, the only way to recover from this is to manually edit thetemplates
database table and reset thepageClass
for theuser
template toUser
. Maybe this should be caught by ProcessWire, to avoid people accidentally locking themselves out of the site (the error occurs both on the backend and the frontend).Actual behavior
After saving the user template with a custom page class, I get the following error:
Steps to reproduce the issue
$config->advanced = true;
to be able to edit theuser
template.MemberUser
(I also tried the FQCN\ProcessWire\MemberUser
).Setup/Environment
The text was updated successfully, but these errors were encountered: