Inclusion of start.php

Hi Everyone.

Could someone please explain to me why a page that is included by the page handler includes the engine/start.php? The page handler file already includes this file.

Are there times one will call the file directly rather than use the page handler? If so, isn't the appropriate method to use an action?

Thank You.

 

  • The development of Elgg was incremental. I think (I wasn't around then) originally the pages were called directly and then over time they were moved to used page handlers. I also have a sneaking susicipion that the include of Elgg's boot script was left in just to be safe.

    The plan is to clean this kind of thing up in the plugins for the 1.8 release of Elgg.

    In general, plugins should avoid calling a page directly but use the page handling system. This allows other plugins to override the page handler of a plugin (or some section of the core) and create their own pages.

    We've also thrown around adding a better routing system but I think you brought that up before...

  • Hi I've realised one of my plugins has a mix (for a me, a confusing mix) of page calls - some using the page handler - some going straight to the /mod/ ...which doesn't look good in the browser.

    for example;

    add_submenu_item(elgg_echo('myplugin:everyone'),$CONFIG->wwwroot."mod/myplugin/everyone.php");
                    add_submenu_item(elgg_echo('myplugin:search'),$CONFIG->wwwroot."mod/myplugin/mypluginbycountry.php");
                    add_submenu_item(elgg_echo('myplugin:featured'),$CONFIG->wwwroot."mod/myplugin/featured.php");
                    add_submenu_item(elgg_echo('myplugin:your'),$CONFIG->wwwroot."pg/myplugin/" . $_SESSION['user']->username);
                    add_submenu_item(elgg_echo('myplugin:friends'),$CONFIG->wwwroot."pg/myplugin/" . $_SESSION['user']->username . "/friends/");

    I also have:

        register_page_handler('myplugin','myplugin_page_handler');
        function myplugin_page_handler($page) {
            // The first component of a myplugin URL is the username
            if (isset($page[0])) {
                set_input('username',$page[0]);
            }
            // The second part dictates what we're doing
            if (isset($page[1])) {
                switch($page[1]) {
                    case "read":        set_input('mypluginpost',$page[2]);
                                @include(dirname(__FILE__) . "/read.php");
                                break;
                    case "friends":        @include(dirname(__FILE__) . "/friends.php");
                                break;
                }
            // If the URL is just 'myplugin/username', or just 'myplugin/', load the standard myplugin index
            } else {
                @include(dirname(__FILE__) . "/index.php");
                return true;
            }
            return false;
        }

     

    So - If i call any of those pages which have /mod/ as they are added to the submenu BUT with pg they get messed with and presented incorrectly - as per the function above. Is there an easy way to incorporate into the page handler function an exception for everyone.php , featured.php and mypluginbycountry.php - i think that'd solve the problem?