Results 1 to 3 of 3

Thread: Page not found

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Location
    Vancouver, BC
    Posts
    19
    Thanks
    2
    Thanked 17 Times in 5 Posts

    Default Page not found

    Hi guys,
    I've started playing around with designing my own plug-in. So far the guides have been great and I think I have a handle on what's going on. What I want to do is call my plug-in from a link and have it display content on the main page. However, when I try to call a page such as "http://mysite.com/index?page=my_plugin" I receive all the content that I have associated with theme_index_main with "Page not found" tagged on at the very end. So everything seems to be working except for that little message. I've searched and searched, but I can't find any help. I'm sure I've probably confused something along the way. Any help would be greatly appreciated! I've included a snippet of my code and file structure below.
    Directories are as follows:
    /content/plugins/my_plugin
    my_plugin.php
    /templates
    my_template.php
    /languages
    my_plugin_language.php

    PHP Code:
    <?php
    /**
     * name: My Plugin
     * description: Test plug-in
     * version: 0.1
     * folder: my_plugin
     * class: MyPlugin
     * hooks: theme_index_top, theme_index_main
      */
     
    class MyPlugin
    {
        public function 
    theme_index_top($h)
        {
            if(
    $h->isPage('my_plugin')){
                
    $h->pageTitle $h->lang["my_plugin"];
            }
        }
        public function 
    theme_index_main($h)
        {
            if (
    $h->isPage('my_plugin')) {
                
    $this->mainPage($h);
            }
        }
        
        public function 
    mainPage($h)
        {
            
    $h->displayTemplate('my_template');
        }

        
    }
    ?>

  2. #2
    Former lead dev Nick's Avatar
    Join Date
    Jun 2009
    Location
    Kakamigahara, Japan
    Posts
    2,859
    Blog Entries
    88
    Thanks
    482
    Thanked 806 Times in 526 Posts

    Default

    You need to return true or false after displaying your template:

    PHP Code:
    public function theme_index_main($h
        { 
            if (
    $h->isPage('my_plugin')) { 
                
    $this->mainPage($h); 
                return 
    true;
            } 
        } 
    The reason is the theme_main_index plugin hook in index.php is used to override the default page, which just happens to be 404error.php:

    PHP Code:
    <!-- MAIN -->
                                <?php     
                                    
    // plugin hook
                                
    $result $h->pluginHook('theme_index_main');
                                if (!
    $result) {
                                    
    $h->displayTemplate($h->pageName); // default is 404error.php
                                
    }
                                
    ?>
    $result is actually an array of values returned from all plugins using the hook, so even returning false will make $result pass the if condition. If nothing at all is returned, "Page not found" will be shown.

  3. Thanked by:


  4. #3
    Junior Member
    Join Date
    Feb 2010
    Location
    Vancouver, BC
    Posts
    19
    Thanks
    2
    Thanked 17 Times in 5 Posts

    Default

    Hi Nick,
    That fixed it right up, thank you so much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •