Add entry admin dashboard


#1

Hi everyone,

I want to use the filter “admin_navigation_main” (or any other filter/hook) to add an entry to the admin navigation. I would like this entry to point to a file located somewhere inside the views folder of the plugin folder (let’s say /MyPlugin/views/admin/index/test.php). I checked the SimplePage plugin but I fail to understand how that works exactly, plus I did not find any other topic in the forum or explanation in the documentation about how to implement this.

What I tried so far (following the indication from this other topic: How to add a view to admin dashboard?)

  • I added the hook define_acl and added the Zend_Acl_Resource “MyPlugin_Index” (the same name I set in the “resource” field in the admin_navigation_main filter);
  • I created an “IndexController.php” file under “controllers” with a “testAction” calling the views under “admin/index/test.php”

However, I get a 404 error when clicking on the entry on the link in the admin dashboard.

What I am doing wrong?

Thanks in advance!
Best


#2

In a plugin, your controllers should have their class names prefixed with the name of the plugin (so, the file IndexController.php should contain a class MyPlugin_IndexController

You didn’t specify what you called the class but that’s a possible issue. The other thing you didn’t specify is what the URL you added to the nav was. The location of your view should be fine for what you’ve indicated.


#3

Thanks for the answer!
The class in the IndexController.php was already correctly named as of your indication:

class MyPlugin_IndexController extends Omeka_Controller_AbstractActionController
{
  public function indexAction()
  {   
    $this->_helper->redirector('test');
    return;
  }
}

The code in the filterAdminNavigationMain is as follow:

    $nav[] = array(
      'label' => __('My test link'),
      'uri' => url('my-plugin'),
      'resource' => 'MyPlugin_Index',
    );
    return $nav;

To me it is also not clear what the “privilege” entry in the nav can be used for.


#4

Do you actually have the testAction and test view still? What you’ve shown is just the indexAction but you’re redirecting.

The “resource” entry is used for ahead-of-time permission checking: the permission check will happen no matter what, but putting the correct resource in the nav will just make the nav not contain entries the current user doesn’t have permission to visit. You can leave it out, which will just mean the entry is always there.


#5

Thanks for your reply.

I do not have a testAction in the IndexController.php, I do have the test.php still.
I think my main problem is that I am not quiet understanding how to set the nav in the filterAdminNavigationMain filter, in order to call a particular xxxAction (in my case the indexAction but I could also define another one), which in turns call a file in the view (in my case, the test.php).

Isn’t the resource also used to specify which controller should be used (in my case the IndexController.php of MyPlugin)?


#6

As I stated above, the resource key in the nav array is only used for ahead-of-time permissions checking.

The URL determines what module, controller, and action will be used: in your case if the URL is “my-plugin” then you’re referring to the my-plugin module (i.e., your plugin), and since the URL doesn’t go on to specify a controller or action you’ll get the default of “index” for both. (This is just for the default routing, you can specify your own that follows different rules.)

A “blank” action, or one that doesn’t specify something else to render, will by default render a view that matches the controller and action name: in this case on the admin side a blank indexAction would be looking for plugins/MyPlugin/views/<admin or shared>/index/index.php.

You have one more wrinkle in your example: your provided indexAction tries to redirect to the action test, but since you don’t actually have a testAction that’s not going to work.