ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

creating own module

June 08, 2007 6:01am

Subscribe [4]
  • #1 / Jun 08, 2007 6:01am

    thisconnect.be's avatar

    thisconnect.be

    73 posts

    Hi all,

    I’am trying to create my own module. The CP part is ready and works. But now i want to create a tag to implement on the front side.

    When i use {exp:custom_groups} i get a blank page but no error. I would expect that the small example below would display “kevin”.
    Maybe somebody can provide me with more information on how to do this.

    if ( ! defined('EXT'))
    {
        exit('Invalid file request');
    }
    
    // -----------------------------------------
    //    Begin class
    // -----------------------------------------
    
    class Custom_groups
    {
        var $return_data= '';
        // -------------------------------
        // Constructor
        // -------------------------------
        
        function Custom_groups()
        {
           global $TMPL;
    
             return this->return_data .= "kevin";
        }
        // END
    }
  • #2 / Jun 08, 2007 7:14am

    ExpressionEngineer's avatar

    ExpressionEngineer

    148 posts

    this line:

    return this->return_data .= "kevin";

    should be (notice the $ before the word “this”

    return $this->return_data .= "kevin";
  • #3 / Jun 08, 2007 10:49am

    Derek Jones's avatar

    Derek Jones

    7561 posts

    You will want to make sure that you have error reporting turned on in the control panel, that you are logged in to the front side of your site so that the errors would be visible, and also make sure that display_errors is turn On on the server.  That code will definitely give you an error, a T_OBJECT_OPERATOR parse error, specifically.

  • #4 / Jun 08, 2007 10:55am

    thisconnect.be's avatar

    thisconnect.be

    73 posts

    ok,

    thanks for the tips.

    I have some more questions what i want to do is something like {exp:custom_groups ids="1|3|3&5"}show content here if the user is in one of the groups provided in the tag. Which i check in my own database.{/exp:custom_groups}

    Here is the code i have so far:
    Do i need to return true or false or something? I dont quite understand yet how to accomplish this?

    class Custom_groups
    {
        var $return_data= '';
        // -------------------------------
        // Constructor
        // -------------------------------
        
        function Custom_groups()
        {
           global $TMPL,$DB,$SESS;
            
            $select = "select * from exp_customgroups_users where userid=".$SESS->userdata['user_id'];
            
             return $this->return_data .= $TMPL->fetch_param('id');
        }
        // END
    }
  • #5 / Jun 08, 2007 11:19am

    Derek Jones's avatar

    Derek Jones

    7561 posts

    You’ll want to return either the tagdata, or nothing, after parsing your parameter and comparing it to the values in your database.

  • #6 / Jun 20, 2007 5:59am

    thisconnect.be's avatar

    thisconnect.be

    73 posts

    Hi guys,

    I still didnt found out how to fix it.
    Can you guys help me out.
    The backoffice works perfect. The only thing i want to do now is:
    {if custom_groups == "2"}
    show stuff
    {if:else}
    show other stuff
    {/if}

    How do you make the template call the function? It seems it never gets called?
    Here is my code so far:

    function Custom_groups()
        {
           global $TMPL,$DB,$SESS,$FNS;
            
            $select = "select groupid from exp_customgroups_users where userid=".$SESS->userdata['user_id'];
            
            $query = $DB->query($select);
            echo $query->row['groupid'];
            $cond = array();
            
            if($query[0]['groupid'] == $TMPL->fetch_param('id'))
            {
                $cond['custom_groups'] = 'TRUE';
            }
            else
            {
                $cond['custom_groups'] = 'FALSE';
            }
            
            $tagdata = $FNS->prep_conditionals($tagdata, $cond);
        }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases