Jump to content

How to create quick variables like $users, $roles etc..


Recommended Posts

Posted

Users are just pages, but we can access them through $users. How is that done? I know that Users class extends PagesType, but I don't find anywhere how $users is created and how it filters that to include only pages with user template (or /access/users/ children).

What I want to achieve is to have new $orders variable which is shortcut to $pages->find("template=order").

Posted

I think I found it:

core/ProcessWire.php:

<?php
if(!$t = $templates->get('user')) throw new WireException("Missing system template: 'user'"); 
$users = new Users($t, $config->usersPageID); 
Wire::setFuel('users', $users); 
Posted

To use PagesType, you have to specify a template and parent_id to the constructor. You actually don't need to extend PagesType unless you want to. I think you could achieve what you are wanting to do just like this:

<?php

$template = $templates->get('order');
$parent = $pages->get('/orders/'); 

$orders = new PagesType($template, parent->id); 
Posted

Thanks Ryan. I am doing this from autoload module, so it seems to require this too:

Wire::setFuel('orders', $orders);

It works nicely!

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...