thetuningspoon Posted January 23, 2015 Share Posted January 23, 2015 This is probably a Ryan question, but perhaps someone else has some experience with extending the PagesType class. Basically, I'm trying to figure out how to extend the PagesType class so that I can create a new API variable like Ryan did with $users. I started by extending the Page class so that I can easily create new objects which are stored like a regular page, but have some additional properties and methods. This is working fine. But now I want to be able to grab and manipulate all of those matching pages from within my module and templates without having to use the $pages variable. Ryan's Users class extends the PagesType class, but it's not clear to me from looking at it how the Users/PageType class creates the $users variable. I did a search on all of ProcessWire's codebase for where the $users fuel is being set, but I can't find it! I can't seem to wrap my head around how the PagesType class can be used to get this all working or where it is actually being instantiated. If anyone can point me in the right direction it would be much appreciated. Link to comment Share on other sites More sharing options...
SteveB Posted January 23, 2015 Share Posted January 23, 2015 Wouldn't it be easier to extend the page class, adding your methods and properties and still be able to work with these new superDuperPages with all the usual API tools? Maybe you telling us more about what you hope to achieve would bring better answers. Link to comment Share on other sites More sharing options...
thetuningspoon Posted January 23, 2015 Author Share Posted January 23, 2015 Thanks for the reply, SteveB. Wouldn't it be easier to extend the page class, adding your methods and properties and still be able to work with these new superDuperPages with all the usual API tools? Maybe you telling us more about what you hope to achieve would bring better answers. I am extending the Page class and that part is working well. I am creating several objects, one is a customer. So my Customer class extends the Page class. But now I would like to have a Customers object as well that stores all of the Customers and lets me access them from within my template and module using a $customers variable instead of using $pages. My first thought was that this would mean extending the Pages class, but the way that Ryan did it with the Users class was to extend PagesType. Link to comment Share on other sites More sharing options...
thetuningspoon Posted January 24, 2015 Author Share Posted January 24, 2015 Got it! I found the Permissions class which is also based on PagesType and was able to find its instantiation in ProcessWire.php, which was helpful. I had to add the following to the init() method in my module: $customers = new Customers($this->templates->get('si-customers'), $this->pages->get("template=si-customers")); // Instantiates the Customers class $this->wire('customers', $customers); // Make the $customers variable available to templates My Customers class right now is just: <?php class Customers extends PagesType {} And is then required at the top of my module. 4 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