Jump to content

Creating new admin page


Adam Kiss
 Share

Recommended Posts

Hi Ryan,

I need to create new page in admin section. I'd like to add it in menu between PAGES and MODULES (or whatever the next item is).

I also like to load pages with hardcoded query, and list them in this order:

  $page->title   |   $parent->title   |   $page->intFieldValue   |   $page->edit()->url

I believe, that query and table aren't problem. The problem is where to create the file itself and how to add it into the admin menu. Also, I would like to hook this file to permissions system (PW2.0)

Thanks!

Link to comment
Share on other sites

To add a new menu item in the admin, you just go in there and add a page like you would anywhere else (and use the 'admin' template for that page, or one of your own if you prefer). If you want it to live between 'Pages' and 'Modules' then just drag it between those two.

If this is something that you want to do automatically (like as part of a module installer) let me know and I'll post a code example.

My understanding is that you want to display a custom HTML table of pages on your new admin page. You can go about this in two ways:

Option 1

You can do it the same way as you would for any other template in your site. Only you would select your new template for that page rather than the 'admin' template. You would set access with the page (2.0) or with the template (2.1). The advantage of this approach is that it's really easy. The disadvantage is that your page may not look like the rest of the admin or use it's systems (which may or may not be useful to your need).

Option 2

Use the 'admin' template for your page, create a new 'Process' module and install it. When you edit your new page, it will ask you what Process it should run, and you'll select the new Process module you created. This is the approach you want to take if you want to maintain a consistent admin experience or you want to package your functionality into a reusable module.

Here's an example of how to create a Process module:

/site/modules/ProcessHello.module

<?php
class ProcessHello extends Process {

    public static function getModuleInfo() {
        return array(
            'title' => 'Hello',
            'summary' => 'Simple Process module demo',
            'version' => 001,
            );
    }

    public function execute() {
        return "<p><a href='./hi'>hi</a> or <a href='./bye'>bye</a></p>";
    }

    public function executeHi() {
        $this->message("Well hello"); 
        return "<p>You clicked hi!</p>";
    }

    public function executeBye() {
        $this->setFuel('processHeadline', 'Goodbye?'); 
        $this->error('Not so fast!'); 
        return "<p>You clicked bye!</p>";
    }
}

Regarding your question about permissions: The user must have access to the page your Process is on before they can execute it. And they will already by default (unless you change around the page/template permissions). But in PW 2.0, they must also have access to a permission with the same name as the module. PW 2.0 installs that automatically with your module. This is only applicable to non-superuser roles (superuser can already access everything regardless of permission).

In 2.1, PW doesn't install a permission and access to the Process is assumed if user has access to the page it's on.  If you want PW 2.1 to behave like PW 2.0 and require a specific permission before it'll run the module, you want to specify it in your getModuleInfo function:

<?php

    public static function getModuleInfo() {
        return array(
            'title' => 'Hello',
            'summary' => 'Simple Process module demo',
            'version' => 001,
            'permission' => 'name-of-permission', // NOTE THIS 
            );
    }

Replace 'name-of-permission' with the permission name you want it to require. It can be any existing permission, or one that you've created.

Your module can also check other permissions on-the-fly, but I won't get into that here unless someone wants me to.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...


hi ryan

is  it wrong if i embed templates-admin/default.php header code inside my page?

for example, i have create a new page inside admin with a custom template i have made

and inside this template i have include the attached file.

for now everything seems to work ok 


admin-head.php

Link to comment
Share on other sites

It seems okay to me. I would double check that you aren't getting any errors by enabling debug mode. But if it works, I can't currently think of any problems with doing it. 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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