[Solved] PluginController 'incude_once'

Feed 7 posts, 2 voices

Avatar
70 posts

Hello,

I’m currently writing on a two plugins for frog and came around the problem when including (with autoload) the controller in the plugin/index.php file.

I hunted down PluginController.php line 68 to use ‘include’ instead of ‘include_once’. Can someone please change this?

Thanks
M

 
Avatar
651 posts

What exactly is your problem? Can you describe it please? Then I’d have an idea why you want the change, not that I’m opposed to the change by the way.

 
Avatar
70 posts

Sure this is my plugin/index.php

<?php
require_once('PageMetadataController.php');
PageMetadataController::Init();
?>

And this the init method:

<?php ...
  public static function Init() {
    // Register plugin
    Plugin::setInfos(...));
    // Register controller
    Plugin::addController(self::PLUGIN_ID, __('Page Metadata'), null, false);
    // The callbacks for the backend
    Observer::observe('view_page_edit_tabs', __CLASS__.'::callback_view_page_edit_tabs');
  }
... ?>

The idea is that the controller takes care of the plugin handling. I have the plugin_id also as a constant and do not want to repeat it in plugin/index.php and in plugin/controller.php.

Therefore I use this code:

<?php ... class PageMetadataController extends PluginController {
  /* Plugin information */
  const PLUGIN_ID      = "page_metadata";
  const PLUGIN_VERSION = "0.0.1";
... ?>

Hope this clarifies it a little bit.

 
Avatar
651 posts

I understand where the problem is coming from…. I must say I didn’t expect anyone to try and write their own plugin controller instead of just using the normal method to initialize the plugin. I also don’t entirely understand why you would want to?

That just makes it needlessly complex?

What you want to do in the controller doesn’t belong there in my opinion… it belongs in the index.php file. That’s how it was designed and there is a reason.

You could have multiple controllers in a single plugin for example. That would become rather difficult in your scenario.

 
Avatar
70 posts

I must say I didn’t expect anyone to try and write their own plugin controller instead of just using the normal method to initialize the plugin

You got me wrong. I’m writing an admin controller. Therefore I have a controller anyway and I use the provided controller.

That just makes it needlessly complex?

Not necessarily. I can show you the complete plugin once I’m finished.

it belongs in the index.php file. That’s how it was designed and there is a reason.

Ok, the way I had it before was plugin/index.php:

    Plugin::setInfos(array(
        'id'          => PageMetadataController::PLUGIN_ID,

But as you can see, the class is also included because I access the constant, so I’ll run into the same problems.

You could have multiple controllers in a single plugin for example. That would become rather difficult in your scenario.

I’m not saying that this method should be used in any case, but for simple plugins I think it’s elegant. But either way, if I access the constant from the plugin/index.php I get the same error. Therefore, please change from ‘include’ to ‘include_once’ in PluginController.

 
Avatar
70 posts

Issued an official feature request.

 
Avatar
651 posts

I’ll implement the change since its not a real big thing and generally makes Frog more robust.. but as a programmer I must say you seem to be doing a whole number of things just to prevent yourself from having to write the plugin id twice… doesn’t make sense to me.

 
Avatar
70 posts

Thanks Martijn,

well, it’s not only the ID. It’s also the registering of the observers and the admin tab as well as the version information ;)

I’ll change this behaviour (maybe) for the next plug-ins ;)

Have a save trip to Japan
M