valan Posted May 4, 2017 Share Posted May 4, 2017 There is excellent article here https://processwire.com/docs/tutorials/using-custom-page-types-in-processwire/ by @LostKobrakai that describes how to use custom page types and extend the Page class. Q: How to extend (e.g. w/o hooks, using method described in article) core Users and User classes and reload $users and $user api variables (they are locked) with new/extended classes? Currently I think about changing User to MyUser class in systems tab (e.g. set another class to be used for 'user' template) and installing module like below. As you can see it adds $myusers and $myuser api variables but I'm not sure that it won't conflict with core. // MyUsers.php class MyUsers extends Users { public function __construct(ProcessWire $wire, $templates = array(), $parents = array()) { parent::__construct($wire, $templates, $parents); $this->setPageClass('MyUser'); } // my non-overlapping methods here ... } // MyUser.php class MyUser extends User { // my non-overlapping methods here ... } class ResourceUser extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'Extend Users and User', 'version' => 100, 'autoload' => true, 'singular' => true, ]; } public function __construct() { require_once(dirname(__FILE__) . '/MyUsers.php'); require_once(dirname(__FILE__) . '/MyUser.php'); } public function init() { $pagesType = new MyUsers($this->wire); $this->wire('myusers', $pagesType, true); $page = new MyUser; $this->wire('myuser', $page, true); } } Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 5, 2017 Share Posted May 5, 2017 As long as you don't overwrite the core api variables you can do whatever you need to do. $user is not locked, only $users is and here's a bit about the difficulties to extend those: https://github.com/ryancramerdesign/ProcessWire/issues/1412 2 Link to comment Share on other sites More sharing options...
valan Posted May 5, 2017 Author Share Posted May 5, 2017 @LostKobrakai - thank you! link is very helpful. P.S. and thank you for article - helped me a lot to better structure and maintain the code. 1 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