leode Posted June 19 Share Posted June 19 Hello Guys! I read the article https://processwire.com/blog/posts/pw-3.0.152/ and want to add some custom methods to all of my pages. As I understand, when I add /site/classes/DefaultPage.php with class DefaultPage extends Page {} and put in my properties and methods, they should be available to all pages. Here is the code I tried: <?php namespace ProcessWire; class DefaultPage extends Page { public function test() { return 'test'; } } However, this does not work (Exception: Method ArticlePage::test does not exist or is not callable in this context) page()->get('/mytestpage/')->test() I would have guessed that since HomePage extends Page and all Page instances are now DefaultPage, my test() method would work. Is there no other way than using hooks to add custom methods to have them on all pages (HomePage, basic-page, my custom ones, etc.)? Thank you for your help! Link to comment Share on other sites More sharing options...
ngrmm Posted June 19 Share Posted June 19 @leode you also edited your config.php right? Link to comment Share on other sites More sharing options...
leode Posted June 19 Author Share Posted June 19 Yes, other methods fro custom page types work fine. Link to comment Share on other sites More sharing options...
iank Posted June 19 Share Posted June 19 @leode, you'll have to make sure your page classes now extend DefaultPage, rather than Page: <?php namespace ProcessWire; class ArticlePage extends DefaultPage //not Page { //your article page specific methods } ?> <? pages()->get('/mytestpage/')->test(); //should now work 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now