You are viewing the PKP Support Forum | PKP Home Wiki

Creating new plugin - 404 Error

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

Creating new plugin - 404 Error

Postby rania » Thu Sep 15, 2011 6:51 am

Hello all!

Based on requests from our latest journal installation, we changed the OJS code to implement the 'Browse By' a setting name (e.g types, disciplines etc.). Currently I am working to develop this functionality as a plugin in order to contribute it to the community, but I have some problems (maybe I should mention that this is my first OJS plugin :roll: ), so any help will be deedply appreciated!

First of all I should mention that I work with OJS 2.3.5 and I install the plugin manually: I created a folder in plugins/generic/browse and put all the code there. Also, I manually added the browsePlugin in versions Table and the plugin is enabled.
So, the register function in BrowsePlugin.inc.php is the following:
Code: Select all
function register($category, $path) {
      if (parent::register($category, $path)) {      
         if ($this->getEnabled()) {
            $BrowseDAO = &new BrowseDAO();
            $returner = &DAORegistry::registerDAO('BrowseDAO', $BrowseDAO);
            // Handler for public thesis abstract pages
            HookRegistry::register('LoadHandler', array($this, 'handleRequest'));   
         return true;
      return false;

Then, the handler is loaded:
Code: Select all
function handleRequest($hookName, $args) {
      $page =& $args[0];
      $op =& $args[1];
      $sourceFile =& $args[2];

      // If the request is for the log analyzer itself, handle it.
      if ($page === 'browse') {
         Registry::set('plugin', $this);
         define('HANDLER_CLASS', 'BrowseHandler');
         return true;

      return false;

In BrowseHandler.inc.php, I have specified index(), which loads a simple test.tpl (this template justs prints a test paragraph):
Code: Select all
function index()
      $templateManager =& TemplateManager::getManager();

So, the URL: http://www.myJournalUrl.../index.php/{journal_initials}/browse should show the test paragraph, but instead it displays 404 error :oops: :shock:
Code: Select all
Stack Trace:

File: C:\xampp\htdocs\ojs_2.3.5_onlinereader\lib\pkp\classes\core\PKPPageRouter.inc.php line 230
Function: Dispatcher->handle404()

File: C:\xampp\htdocs\ojs_2.3.5_onlinereader\lib\pkp\classes\core\Dispatcher.inc.php line 129
Function: PKPPageRouter->route(Object(Request))

File: C:\xampp\htdocs\ojs_2.3.5_onlinereader\lib\pkp\classes\core\PKPApplication.inc.php line 180
Function: Dispatcher->dispatch(Object(Request))

File: C:\xampp\htdocs\ojs_2.3.5_onlinereader\index.php line 65
Function: PKPApplication->execute()

What am I doing wrong? I have tried various ways to do this, based on other generic plugins and still the same problem! :(

Also, how can I specify to load different functions based on the URL? (e.g. if the URL is browse/types, it should load the function types() from BrowseHandler.inc.php)

Can someone please help me with this.

Thank you in advance,

Posts: 35
Joined: Thu Nov 08, 2007 1:37 am

Re: Creating new plugin - 404 Error

Postby jmacgreg » Sun Sep 18, 2011 9:03 pm

Hi Rania,

It looks like you may have tried getting this working by using the COUNTER plugin as a template (which is exactly how I would've gone about doing so, as well). It looks like you've stripped out a few possibly necessary lines from the index() function in your BrowseHandler.inc.php file, particularly the following:

Code: Select all
$plugin =& $this->plugin;

Try adding those lines, and let us know if you have any better luck. I'll ask a more senior developer if he can get back to you about your other question.

Posts: 4191
Joined: Tue Feb 14, 2006 10:50 am

Re: Creating new plugin - 404 Error

Postby asmecher » Sun Sep 18, 2011 11:39 pm

Hi Rania,

The most likely (and frustrating) problem is that the version entry in the database is not complete. You can tell this because the register() function will never get called -- try throwing a few "echo" statements in there to see whether that's the case. You can get the version entry to be created automatically by running the upgrade script (php tools/upgrade.php upgrade). (I'm assuming this is a development install? Otherwise be sure that your installation is in a good state before you run that.)

Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: Creating new plugin - 404 Error

Postby rania » Fri Sep 23, 2011 8:24 am

Hello Alec and James!

Thank you very much for the replies! :D

For anyone else who may experience the same problem, it had to do with the registration in the database. Running the upgrade script (php tools/upgrade.php upgrade), as Alec pointed out, fixed the problem. :) The logs indeed showed that the register() function was called only when I got the plugin enabled (from the administrator interface) and only then.

I am happy to report that the plugin is almost ready, just finishing some testing... So, I will be contributing it, sortly! :D

Again many many thanks!


Posts: 35
Joined: Thu Nov 08, 2007 1:37 am

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest